001
014
015 package com.liferay.portlet.documentlibrary.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.CharPool;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.SetUtil;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
037
038 import com.liferay.portlet.documentlibrary.NoSuchContentException;
039 import com.liferay.portlet.documentlibrary.model.DLContent;
040 import com.liferay.portlet.documentlibrary.model.impl.DLContentImpl;
041 import com.liferay.portlet.documentlibrary.model.impl.DLContentModelImpl;
042 import com.liferay.portlet.documentlibrary.service.persistence.DLContentPersistence;
043
044 import java.io.Serializable;
045
046 import java.util.Collections;
047 import java.util.HashMap;
048 import java.util.HashSet;
049 import java.util.Iterator;
050 import java.util.List;
051 import java.util.Map;
052 import java.util.Set;
053
054
066 @ProviderType
067 public class DLContentPersistenceImpl extends BasePersistenceImpl<DLContent>
068 implements DLContentPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = DLContentImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
080 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
083 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
086 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
089 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R",
091 new String[] {
092 Long.class.getName(), Long.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
098 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R",
100 new String[] { Long.class.getName(), Long.class.getName() },
101 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
102 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
103 DLContentModelImpl.VERSION_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
105 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
107 new String[] { Long.class.getName(), Long.class.getName() });
108
109
116 @Override
117 public List<DLContent> findByC_R(long companyId, long repositoryId) {
118 return findByC_R(companyId, repositoryId, QueryUtil.ALL_POS,
119 QueryUtil.ALL_POS, null);
120 }
121
122
135 @Override
136 public List<DLContent> findByC_R(long companyId, long repositoryId,
137 int start, int end) {
138 return findByC_R(companyId, repositoryId, start, end, null);
139 }
140
141
155 @Override
156 public List<DLContent> findByC_R(long companyId, long repositoryId,
157 int start, int end, OrderByComparator<DLContent> orderByComparator) {
158 boolean pagination = true;
159 FinderPath finderPath = null;
160 Object[] finderArgs = null;
161
162 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163 (orderByComparator == null)) {
164 pagination = false;
165 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R;
166 finderArgs = new Object[] { companyId, repositoryId };
167 }
168 else {
169 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R;
170 finderArgs = new Object[] {
171 companyId, repositoryId,
172
173 start, end, orderByComparator
174 };
175 }
176
177 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (DLContent dlContent : list) {
182 if ((companyId != dlContent.getCompanyId()) ||
183 (repositoryId != dlContent.getRepositoryId())) {
184 list = null;
185
186 break;
187 }
188 }
189 }
190
191 if (list == null) {
192 StringBundler query = null;
193
194 if (orderByComparator != null) {
195 query = new StringBundler(4 +
196 (orderByComparator.getOrderByFields().length * 3));
197 }
198 else {
199 query = new StringBundler(4);
200 }
201
202 query.append(_SQL_SELECT_DLCONTENT_WHERE);
203
204 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
205
206 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(DLContentModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 qPos.add(companyId);
229
230 qPos.add(repositoryId);
231
232 if (!pagination) {
233 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
234 start, end, false);
235
236 Collections.sort(list);
237
238 list = Collections.unmodifiableList(list);
239 }
240 else {
241 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
242 start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
271 @Override
272 public DLContent findByC_R_First(long companyId, long repositoryId,
273 OrderByComparator<DLContent> orderByComparator)
274 throws NoSuchContentException {
275 DLContent dlContent = fetchByC_R_First(companyId, repositoryId,
276 orderByComparator);
277
278 if (dlContent != null) {
279 return dlContent;
280 }
281
282 StringBundler msg = new StringBundler(6);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("companyId=");
287 msg.append(companyId);
288
289 msg.append(", repositoryId=");
290 msg.append(repositoryId);
291
292 msg.append(StringPool.CLOSE_CURLY_BRACE);
293
294 throw new NoSuchContentException(msg.toString());
295 }
296
297
305 @Override
306 public DLContent fetchByC_R_First(long companyId, long repositoryId,
307 OrderByComparator<DLContent> orderByComparator) {
308 List<DLContent> list = findByC_R(companyId, repositoryId, 0, 1,
309 orderByComparator);
310
311 if (!list.isEmpty()) {
312 return list.get(0);
313 }
314
315 return null;
316 }
317
318
327 @Override
328 public DLContent findByC_R_Last(long companyId, long repositoryId,
329 OrderByComparator<DLContent> orderByComparator)
330 throws NoSuchContentException {
331 DLContent dlContent = fetchByC_R_Last(companyId, repositoryId,
332 orderByComparator);
333
334 if (dlContent != null) {
335 return dlContent;
336 }
337
338 StringBundler msg = new StringBundler(6);
339
340 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
341
342 msg.append("companyId=");
343 msg.append(companyId);
344
345 msg.append(", repositoryId=");
346 msg.append(repositoryId);
347
348 msg.append(StringPool.CLOSE_CURLY_BRACE);
349
350 throw new NoSuchContentException(msg.toString());
351 }
352
353
361 @Override
362 public DLContent fetchByC_R_Last(long companyId, long repositoryId,
363 OrderByComparator<DLContent> orderByComparator) {
364 int count = countByC_R(companyId, repositoryId);
365
366 if (count == 0) {
367 return null;
368 }
369
370 List<DLContent> list = findByC_R(companyId, repositoryId, count - 1,
371 count, orderByComparator);
372
373 if (!list.isEmpty()) {
374 return list.get(0);
375 }
376
377 return null;
378 }
379
380
390 @Override
391 public DLContent[] findByC_R_PrevAndNext(long contentId, long companyId,
392 long repositoryId, OrderByComparator<DLContent> orderByComparator)
393 throws NoSuchContentException {
394 DLContent dlContent = findByPrimaryKey(contentId);
395
396 Session session = null;
397
398 try {
399 session = openSession();
400
401 DLContent[] array = new DLContentImpl[3];
402
403 array[0] = getByC_R_PrevAndNext(session, dlContent, companyId,
404 repositoryId, orderByComparator, true);
405
406 array[1] = dlContent;
407
408 array[2] = getByC_R_PrevAndNext(session, dlContent, companyId,
409 repositoryId, orderByComparator, false);
410
411 return array;
412 }
413 catch (Exception e) {
414 throw processException(e);
415 }
416 finally {
417 closeSession(session);
418 }
419 }
420
421 protected DLContent getByC_R_PrevAndNext(Session session,
422 DLContent dlContent, long companyId, long repositoryId,
423 OrderByComparator<DLContent> orderByComparator, boolean previous) {
424 StringBundler query = null;
425
426 if (orderByComparator != null) {
427 query = new StringBundler(6 +
428 (orderByComparator.getOrderByFields().length * 6));
429 }
430 else {
431 query = new StringBundler(3);
432 }
433
434 query.append(_SQL_SELECT_DLCONTENT_WHERE);
435
436 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
437
438 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
439
440 if (orderByComparator != null) {
441 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442
443 if (orderByConditionFields.length > 0) {
444 query.append(WHERE_AND);
445 }
446
447 for (int i = 0; i < orderByConditionFields.length; i++) {
448 query.append(_ORDER_BY_ENTITY_ALIAS);
449 query.append(orderByConditionFields[i]);
450
451 if ((i + 1) < orderByConditionFields.length) {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN_HAS_NEXT);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN_HAS_NEXT);
457 }
458 }
459 else {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(WHERE_GREATER_THAN);
462 }
463 else {
464 query.append(WHERE_LESSER_THAN);
465 }
466 }
467 }
468
469 query.append(ORDER_BY_CLAUSE);
470
471 String[] orderByFields = orderByComparator.getOrderByFields();
472
473 for (int i = 0; i < orderByFields.length; i++) {
474 query.append(_ORDER_BY_ENTITY_ALIAS);
475 query.append(orderByFields[i]);
476
477 if ((i + 1) < orderByFields.length) {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC_HAS_NEXT);
480 }
481 else {
482 query.append(ORDER_BY_DESC_HAS_NEXT);
483 }
484 }
485 else {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(ORDER_BY_ASC);
488 }
489 else {
490 query.append(ORDER_BY_DESC);
491 }
492 }
493 }
494 }
495 else {
496 query.append(DLContentModelImpl.ORDER_BY_JPQL);
497 }
498
499 String sql = query.toString();
500
501 Query q = session.createQuery(sql);
502
503 q.setFirstResult(0);
504 q.setMaxResults(2);
505
506 QueryPos qPos = QueryPos.getInstance(q);
507
508 qPos.add(companyId);
509
510 qPos.add(repositoryId);
511
512 if (orderByComparator != null) {
513 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
514
515 for (Object value : values) {
516 qPos.add(value);
517 }
518 }
519
520 List<DLContent> list = q.list();
521
522 if (list.size() == 2) {
523 return list.get(1);
524 }
525 else {
526 return null;
527 }
528 }
529
530
536 @Override
537 public void removeByC_R(long companyId, long repositoryId) {
538 for (DLContent dlContent : findByC_R(companyId, repositoryId,
539 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
540 remove(dlContent);
541 }
542 }
543
544
551 @Override
552 public int countByC_R(long companyId, long repositoryId) {
553 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R;
554
555 Object[] finderArgs = new Object[] { companyId, repositoryId };
556
557 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
558 this);
559
560 if (count == null) {
561 StringBundler query = new StringBundler(3);
562
563 query.append(_SQL_COUNT_DLCONTENT_WHERE);
564
565 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
566
567 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
568
569 String sql = query.toString();
570
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 Query q = session.createQuery(sql);
577
578 QueryPos qPos = QueryPos.getInstance(q);
579
580 qPos.add(companyId);
581
582 qPos.add(repositoryId);
583
584 count = (Long)q.uniqueResult();
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, count);
587 }
588 catch (Exception e) {
589 FinderCacheUtil.removeResult(finderPath, finderArgs);
590
591 throw processException(e);
592 }
593 finally {
594 closeSession(session);
595 }
596 }
597
598 return count.intValue();
599 }
600
601 private static final String _FINDER_COLUMN_C_R_COMPANYID_2 = "dlContent.companyId = ? AND ";
602 private static final String _FINDER_COLUMN_C_R_REPOSITORYID_2 = "dlContent.repositoryId = ?";
603 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
604 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
605 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_P",
606 new String[] {
607 Long.class.getName(), Long.class.getName(),
608 String.class.getName(),
609
610 Integer.class.getName(), Integer.class.getName(),
611 OrderByComparator.class.getName()
612 });
613 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
614 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R_P",
616 new String[] {
617 Long.class.getName(), Long.class.getName(),
618 String.class.getName()
619 },
620 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
621 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
622 DLContentModelImpl.PATH_COLUMN_BITMASK |
623 DLContentModelImpl.VERSION_COLUMN_BITMASK);
624 public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
625 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
626 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P",
627 new String[] {
628 Long.class.getName(), Long.class.getName(),
629 String.class.getName()
630 });
631
632
640 @Override
641 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
642 String path) {
643 return findByC_R_P(companyId, repositoryId, path, QueryUtil.ALL_POS,
644 QueryUtil.ALL_POS, null);
645 }
646
647
661 @Override
662 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
663 String path, int start, int end) {
664 return findByC_R_P(companyId, repositoryId, path, start, end, null);
665 }
666
667
682 @Override
683 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
684 String path, int start, int end,
685 OrderByComparator<DLContent> orderByComparator) {
686 boolean pagination = true;
687 FinderPath finderPath = null;
688 Object[] finderArgs = null;
689
690 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
691 (orderByComparator == null)) {
692 pagination = false;
693 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P;
694 finderArgs = new Object[] { companyId, repositoryId, path };
695 }
696 else {
697 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P;
698 finderArgs = new Object[] {
699 companyId, repositoryId, path,
700
701 start, end, orderByComparator
702 };
703 }
704
705 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
706 finderArgs, this);
707
708 if ((list != null) && !list.isEmpty()) {
709 for (DLContent dlContent : list) {
710 if ((companyId != dlContent.getCompanyId()) ||
711 (repositoryId != dlContent.getRepositoryId()) ||
712 !Validator.equals(path, dlContent.getPath())) {
713 list = null;
714
715 break;
716 }
717 }
718 }
719
720 if (list == null) {
721 StringBundler query = null;
722
723 if (orderByComparator != null) {
724 query = new StringBundler(5 +
725 (orderByComparator.getOrderByFields().length * 3));
726 }
727 else {
728 query = new StringBundler(5);
729 }
730
731 query.append(_SQL_SELECT_DLCONTENT_WHERE);
732
733 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
734
735 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
736
737 boolean bindPath = false;
738
739 if (path == null) {
740 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
741 }
742 else if (path.equals(StringPool.BLANK)) {
743 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
744 }
745 else {
746 bindPath = true;
747
748 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
749 }
750
751 if (orderByComparator != null) {
752 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
753 orderByComparator);
754 }
755 else
756 if (pagination) {
757 query.append(DLContentModelImpl.ORDER_BY_JPQL);
758 }
759
760 String sql = query.toString();
761
762 Session session = null;
763
764 try {
765 session = openSession();
766
767 Query q = session.createQuery(sql);
768
769 QueryPos qPos = QueryPos.getInstance(q);
770
771 qPos.add(companyId);
772
773 qPos.add(repositoryId);
774
775 if (bindPath) {
776 qPos.add(path);
777 }
778
779 if (!pagination) {
780 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
781 start, end, false);
782
783 Collections.sort(list);
784
785 list = Collections.unmodifiableList(list);
786 }
787 else {
788 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
789 start, end);
790 }
791
792 cacheResult(list);
793
794 FinderCacheUtil.putResult(finderPath, finderArgs, list);
795 }
796 catch (Exception e) {
797 FinderCacheUtil.removeResult(finderPath, finderArgs);
798
799 throw processException(e);
800 }
801 finally {
802 closeSession(session);
803 }
804 }
805
806 return list;
807 }
808
809
819 @Override
820 public DLContent findByC_R_P_First(long companyId, long repositoryId,
821 String path, OrderByComparator<DLContent> orderByComparator)
822 throws NoSuchContentException {
823 DLContent dlContent = fetchByC_R_P_First(companyId, repositoryId, path,
824 orderByComparator);
825
826 if (dlContent != null) {
827 return dlContent;
828 }
829
830 StringBundler msg = new StringBundler(8);
831
832 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
833
834 msg.append("companyId=");
835 msg.append(companyId);
836
837 msg.append(", repositoryId=");
838 msg.append(repositoryId);
839
840 msg.append(", path=");
841 msg.append(path);
842
843 msg.append(StringPool.CLOSE_CURLY_BRACE);
844
845 throw new NoSuchContentException(msg.toString());
846 }
847
848
857 @Override
858 public DLContent fetchByC_R_P_First(long companyId, long repositoryId,
859 String path, OrderByComparator<DLContent> orderByComparator) {
860 List<DLContent> list = findByC_R_P(companyId, repositoryId, path, 0, 1,
861 orderByComparator);
862
863 if (!list.isEmpty()) {
864 return list.get(0);
865 }
866
867 return null;
868 }
869
870
880 @Override
881 public DLContent findByC_R_P_Last(long companyId, long repositoryId,
882 String path, OrderByComparator<DLContent> orderByComparator)
883 throws NoSuchContentException {
884 DLContent dlContent = fetchByC_R_P_Last(companyId, repositoryId, path,
885 orderByComparator);
886
887 if (dlContent != null) {
888 return dlContent;
889 }
890
891 StringBundler msg = new StringBundler(8);
892
893 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
894
895 msg.append("companyId=");
896 msg.append(companyId);
897
898 msg.append(", repositoryId=");
899 msg.append(repositoryId);
900
901 msg.append(", path=");
902 msg.append(path);
903
904 msg.append(StringPool.CLOSE_CURLY_BRACE);
905
906 throw new NoSuchContentException(msg.toString());
907 }
908
909
918 @Override
919 public DLContent fetchByC_R_P_Last(long companyId, long repositoryId,
920 String path, OrderByComparator<DLContent> orderByComparator) {
921 int count = countByC_R_P(companyId, repositoryId, path);
922
923 if (count == 0) {
924 return null;
925 }
926
927 List<DLContent> list = findByC_R_P(companyId, repositoryId, path,
928 count - 1, count, orderByComparator);
929
930 if (!list.isEmpty()) {
931 return list.get(0);
932 }
933
934 return null;
935 }
936
937
948 @Override
949 public DLContent[] findByC_R_P_PrevAndNext(long contentId, long companyId,
950 long repositoryId, String path,
951 OrderByComparator<DLContent> orderByComparator)
952 throws NoSuchContentException {
953 DLContent dlContent = findByPrimaryKey(contentId);
954
955 Session session = null;
956
957 try {
958 session = openSession();
959
960 DLContent[] array = new DLContentImpl[3];
961
962 array[0] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
963 repositoryId, path, orderByComparator, true);
964
965 array[1] = dlContent;
966
967 array[2] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
968 repositoryId, path, orderByComparator, false);
969
970 return array;
971 }
972 catch (Exception e) {
973 throw processException(e);
974 }
975 finally {
976 closeSession(session);
977 }
978 }
979
980 protected DLContent getByC_R_P_PrevAndNext(Session session,
981 DLContent dlContent, long companyId, long repositoryId, String path,
982 OrderByComparator<DLContent> orderByComparator, boolean previous) {
983 StringBundler query = null;
984
985 if (orderByComparator != null) {
986 query = new StringBundler(6 +
987 (orderByComparator.getOrderByFields().length * 6));
988 }
989 else {
990 query = new StringBundler(3);
991 }
992
993 query.append(_SQL_SELECT_DLCONTENT_WHERE);
994
995 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
996
997 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
998
999 boolean bindPath = false;
1000
1001 if (path == null) {
1002 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
1003 }
1004 else if (path.equals(StringPool.BLANK)) {
1005 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
1006 }
1007 else {
1008 bindPath = true;
1009
1010 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1011 }
1012
1013 if (orderByComparator != null) {
1014 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1015
1016 if (orderByConditionFields.length > 0) {
1017 query.append(WHERE_AND);
1018 }
1019
1020 for (int i = 0; i < orderByConditionFields.length; i++) {
1021 query.append(_ORDER_BY_ENTITY_ALIAS);
1022 query.append(orderByConditionFields[i]);
1023
1024 if ((i + 1) < orderByConditionFields.length) {
1025 if (orderByComparator.isAscending() ^ previous) {
1026 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1027 }
1028 else {
1029 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1030 }
1031 }
1032 else {
1033 if (orderByComparator.isAscending() ^ previous) {
1034 query.append(WHERE_GREATER_THAN);
1035 }
1036 else {
1037 query.append(WHERE_LESSER_THAN);
1038 }
1039 }
1040 }
1041
1042 query.append(ORDER_BY_CLAUSE);
1043
1044 String[] orderByFields = orderByComparator.getOrderByFields();
1045
1046 for (int i = 0; i < orderByFields.length; i++) {
1047 query.append(_ORDER_BY_ENTITY_ALIAS);
1048 query.append(orderByFields[i]);
1049
1050 if ((i + 1) < orderByFields.length) {
1051 if (orderByComparator.isAscending() ^ previous) {
1052 query.append(ORDER_BY_ASC_HAS_NEXT);
1053 }
1054 else {
1055 query.append(ORDER_BY_DESC_HAS_NEXT);
1056 }
1057 }
1058 else {
1059 if (orderByComparator.isAscending() ^ previous) {
1060 query.append(ORDER_BY_ASC);
1061 }
1062 else {
1063 query.append(ORDER_BY_DESC);
1064 }
1065 }
1066 }
1067 }
1068 else {
1069 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1070 }
1071
1072 String sql = query.toString();
1073
1074 Query q = session.createQuery(sql);
1075
1076 q.setFirstResult(0);
1077 q.setMaxResults(2);
1078
1079 QueryPos qPos = QueryPos.getInstance(q);
1080
1081 qPos.add(companyId);
1082
1083 qPos.add(repositoryId);
1084
1085 if (bindPath) {
1086 qPos.add(path);
1087 }
1088
1089 if (orderByComparator != null) {
1090 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1091
1092 for (Object value : values) {
1093 qPos.add(value);
1094 }
1095 }
1096
1097 List<DLContent> list = q.list();
1098
1099 if (list.size() == 2) {
1100 return list.get(1);
1101 }
1102 else {
1103 return null;
1104 }
1105 }
1106
1107
1114 @Override
1115 public void removeByC_R_P(long companyId, long repositoryId, String path) {
1116 for (DLContent dlContent : findByC_R_P(companyId, repositoryId, path,
1117 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1118 remove(dlContent);
1119 }
1120 }
1121
1122
1130 @Override
1131 public int countByC_R_P(long companyId, long repositoryId, String path) {
1132 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R_P;
1133
1134 Object[] finderArgs = new Object[] { companyId, repositoryId, path };
1135
1136 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1137 this);
1138
1139 if (count == null) {
1140 StringBundler query = new StringBundler(4);
1141
1142 query.append(_SQL_COUNT_DLCONTENT_WHERE);
1143
1144 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
1145
1146 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
1147
1148 boolean bindPath = false;
1149
1150 if (path == null) {
1151 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
1152 }
1153 else if (path.equals(StringPool.BLANK)) {
1154 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
1155 }
1156 else {
1157 bindPath = true;
1158
1159 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1160 }
1161
1162 String sql = query.toString();
1163
1164 Session session = null;
1165
1166 try {
1167 session = openSession();
1168
1169 Query q = session.createQuery(sql);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 qPos.add(companyId);
1174
1175 qPos.add(repositoryId);
1176
1177 if (bindPath) {
1178 qPos.add(path);
1179 }
1180
1181 count = (Long)q.uniqueResult();
1182
1183 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1184 }
1185 catch (Exception e) {
1186 FinderCacheUtil.removeResult(finderPath, finderArgs);
1187
1188 throw processException(e);
1189 }
1190 finally {
1191 closeSession(session);
1192 }
1193 }
1194
1195 return count.intValue();
1196 }
1197
1198 private static final String _FINDER_COLUMN_C_R_P_COMPANYID_2 = "dlContent.companyId = ? AND ";
1199 private static final String _FINDER_COLUMN_C_R_P_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
1200 private static final String _FINDER_COLUMN_C_R_P_PATH_1 = "dlContent.path IS NULL";
1201 private static final String _FINDER_COLUMN_C_R_P_PATH_2 = "dlContent.path = ?";
1202 private static final String _FINDER_COLUMN_C_R_P_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = '')";
1203 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP =
1204 new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1205 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
1206 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_LikeP",
1207 new String[] {
1208 Long.class.getName(), Long.class.getName(),
1209 String.class.getName(),
1210
1211 Integer.class.getName(), Integer.class.getName(),
1212 OrderByComparator.class.getName()
1213 });
1214 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP =
1215 new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1216 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1217 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_R_LikeP",
1218 new String[] {
1219 Long.class.getName(), Long.class.getName(),
1220 String.class.getName()
1221 });
1222
1223
1231 @Override
1232 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1233 String path) {
1234 return findByC_R_LikeP(companyId, repositoryId, path,
1235 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1236 }
1237
1238
1252 @Override
1253 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1254 String path, int start, int end) {
1255 return findByC_R_LikeP(companyId, repositoryId, path, start, end, null);
1256 }
1257
1258
1273 @Override
1274 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1275 String path, int start, int end,
1276 OrderByComparator<DLContent> orderByComparator) {
1277 boolean pagination = true;
1278 FinderPath finderPath = null;
1279 Object[] finderArgs = null;
1280
1281 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP;
1282 finderArgs = new Object[] {
1283 companyId, repositoryId, path,
1284
1285 start, end, orderByComparator
1286 };
1287
1288 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
1289 finderArgs, this);
1290
1291 if ((list != null) && !list.isEmpty()) {
1292 for (DLContent dlContent : list) {
1293 if ((companyId != dlContent.getCompanyId()) ||
1294 (repositoryId != dlContent.getRepositoryId()) ||
1295 !StringUtil.wildcardMatches(dlContent.getPath(), path,
1296 CharPool.UNDERLINE, CharPool.PERCENT,
1297 CharPool.BACK_SLASH, true)) {
1298 list = null;
1299
1300 break;
1301 }
1302 }
1303 }
1304
1305 if (list == null) {
1306 StringBundler query = null;
1307
1308 if (orderByComparator != null) {
1309 query = new StringBundler(5 +
1310 (orderByComparator.getOrderByFields().length * 3));
1311 }
1312 else {
1313 query = new StringBundler(5);
1314 }
1315
1316 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1317
1318 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1319
1320 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1321
1322 boolean bindPath = false;
1323
1324 if (path == null) {
1325 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1326 }
1327 else if (path.equals(StringPool.BLANK)) {
1328 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1329 }
1330 else {
1331 bindPath = true;
1332
1333 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1334 }
1335
1336 if (orderByComparator != null) {
1337 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1338 orderByComparator);
1339 }
1340 else
1341 if (pagination) {
1342 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1343 }
1344
1345 String sql = query.toString();
1346
1347 Session session = null;
1348
1349 try {
1350 session = openSession();
1351
1352 Query q = session.createQuery(sql);
1353
1354 QueryPos qPos = QueryPos.getInstance(q);
1355
1356 qPos.add(companyId);
1357
1358 qPos.add(repositoryId);
1359
1360 if (bindPath) {
1361 qPos.add(path);
1362 }
1363
1364 if (!pagination) {
1365 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
1366 start, end, false);
1367
1368 Collections.sort(list);
1369
1370 list = Collections.unmodifiableList(list);
1371 }
1372 else {
1373 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
1374 start, end);
1375 }
1376
1377 cacheResult(list);
1378
1379 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1380 }
1381 catch (Exception e) {
1382 FinderCacheUtil.removeResult(finderPath, finderArgs);
1383
1384 throw processException(e);
1385 }
1386 finally {
1387 closeSession(session);
1388 }
1389 }
1390
1391 return list;
1392 }
1393
1394
1404 @Override
1405 public DLContent findByC_R_LikeP_First(long companyId, long repositoryId,
1406 String path, OrderByComparator<DLContent> orderByComparator)
1407 throws NoSuchContentException {
1408 DLContent dlContent = fetchByC_R_LikeP_First(companyId, repositoryId,
1409 path, orderByComparator);
1410
1411 if (dlContent != null) {
1412 return dlContent;
1413 }
1414
1415 StringBundler msg = new StringBundler(8);
1416
1417 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1418
1419 msg.append("companyId=");
1420 msg.append(companyId);
1421
1422 msg.append(", repositoryId=");
1423 msg.append(repositoryId);
1424
1425 msg.append(", path=");
1426 msg.append(path);
1427
1428 msg.append(StringPool.CLOSE_CURLY_BRACE);
1429
1430 throw new NoSuchContentException(msg.toString());
1431 }
1432
1433
1442 @Override
1443 public DLContent fetchByC_R_LikeP_First(long companyId, long repositoryId,
1444 String path, OrderByComparator<DLContent> orderByComparator) {
1445 List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1446 0, 1, orderByComparator);
1447
1448 if (!list.isEmpty()) {
1449 return list.get(0);
1450 }
1451
1452 return null;
1453 }
1454
1455
1465 @Override
1466 public DLContent findByC_R_LikeP_Last(long companyId, long repositoryId,
1467 String path, OrderByComparator<DLContent> orderByComparator)
1468 throws NoSuchContentException {
1469 DLContent dlContent = fetchByC_R_LikeP_Last(companyId, repositoryId,
1470 path, orderByComparator);
1471
1472 if (dlContent != null) {
1473 return dlContent;
1474 }
1475
1476 StringBundler msg = new StringBundler(8);
1477
1478 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1479
1480 msg.append("companyId=");
1481 msg.append(companyId);
1482
1483 msg.append(", repositoryId=");
1484 msg.append(repositoryId);
1485
1486 msg.append(", path=");
1487 msg.append(path);
1488
1489 msg.append(StringPool.CLOSE_CURLY_BRACE);
1490
1491 throw new NoSuchContentException(msg.toString());
1492 }
1493
1494
1503 @Override
1504 public DLContent fetchByC_R_LikeP_Last(long companyId, long repositoryId,
1505 String path, OrderByComparator<DLContent> orderByComparator) {
1506 int count = countByC_R_LikeP(companyId, repositoryId, path);
1507
1508 if (count == 0) {
1509 return null;
1510 }
1511
1512 List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1513 count - 1, count, orderByComparator);
1514
1515 if (!list.isEmpty()) {
1516 return list.get(0);
1517 }
1518
1519 return null;
1520 }
1521
1522
1533 @Override
1534 public DLContent[] findByC_R_LikeP_PrevAndNext(long contentId,
1535 long companyId, long repositoryId, String path,
1536 OrderByComparator<DLContent> orderByComparator)
1537 throws NoSuchContentException {
1538 DLContent dlContent = findByPrimaryKey(contentId);
1539
1540 Session session = null;
1541
1542 try {
1543 session = openSession();
1544
1545 DLContent[] array = new DLContentImpl[3];
1546
1547 array[0] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1548 companyId, repositoryId, path, orderByComparator, true);
1549
1550 array[1] = dlContent;
1551
1552 array[2] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1553 companyId, repositoryId, path, orderByComparator, false);
1554
1555 return array;
1556 }
1557 catch (Exception e) {
1558 throw processException(e);
1559 }
1560 finally {
1561 closeSession(session);
1562 }
1563 }
1564
1565 protected DLContent getByC_R_LikeP_PrevAndNext(Session session,
1566 DLContent dlContent, long companyId, long repositoryId, String path,
1567 OrderByComparator<DLContent> orderByComparator, boolean previous) {
1568 StringBundler query = null;
1569
1570 if (orderByComparator != null) {
1571 query = new StringBundler(6 +
1572 (orderByComparator.getOrderByFields().length * 6));
1573 }
1574 else {
1575 query = new StringBundler(3);
1576 }
1577
1578 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1579
1580 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1581
1582 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1583
1584 boolean bindPath = false;
1585
1586 if (path == null) {
1587 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1588 }
1589 else if (path.equals(StringPool.BLANK)) {
1590 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1591 }
1592 else {
1593 bindPath = true;
1594
1595 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1596 }
1597
1598 if (orderByComparator != null) {
1599 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1600
1601 if (orderByConditionFields.length > 0) {
1602 query.append(WHERE_AND);
1603 }
1604
1605 for (int i = 0; i < orderByConditionFields.length; i++) {
1606 query.append(_ORDER_BY_ENTITY_ALIAS);
1607 query.append(orderByConditionFields[i]);
1608
1609 if ((i + 1) < orderByConditionFields.length) {
1610 if (orderByComparator.isAscending() ^ previous) {
1611 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1612 }
1613 else {
1614 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1615 }
1616 }
1617 else {
1618 if (orderByComparator.isAscending() ^ previous) {
1619 query.append(WHERE_GREATER_THAN);
1620 }
1621 else {
1622 query.append(WHERE_LESSER_THAN);
1623 }
1624 }
1625 }
1626
1627 query.append(ORDER_BY_CLAUSE);
1628
1629 String[] orderByFields = orderByComparator.getOrderByFields();
1630
1631 for (int i = 0; i < orderByFields.length; i++) {
1632 query.append(_ORDER_BY_ENTITY_ALIAS);
1633 query.append(orderByFields[i]);
1634
1635 if ((i + 1) < orderByFields.length) {
1636 if (orderByComparator.isAscending() ^ previous) {
1637 query.append(ORDER_BY_ASC_HAS_NEXT);
1638 }
1639 else {
1640 query.append(ORDER_BY_DESC_HAS_NEXT);
1641 }
1642 }
1643 else {
1644 if (orderByComparator.isAscending() ^ previous) {
1645 query.append(ORDER_BY_ASC);
1646 }
1647 else {
1648 query.append(ORDER_BY_DESC);
1649 }
1650 }
1651 }
1652 }
1653 else {
1654 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1655 }
1656
1657 String sql = query.toString();
1658
1659 Query q = session.createQuery(sql);
1660
1661 q.setFirstResult(0);
1662 q.setMaxResults(2);
1663
1664 QueryPos qPos = QueryPos.getInstance(q);
1665
1666 qPos.add(companyId);
1667
1668 qPos.add(repositoryId);
1669
1670 if (bindPath) {
1671 qPos.add(path);
1672 }
1673
1674 if (orderByComparator != null) {
1675 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1676
1677 for (Object value : values) {
1678 qPos.add(value);
1679 }
1680 }
1681
1682 List<DLContent> list = q.list();
1683
1684 if (list.size() == 2) {
1685 return list.get(1);
1686 }
1687 else {
1688 return null;
1689 }
1690 }
1691
1692
1699 @Override
1700 public void removeByC_R_LikeP(long companyId, long repositoryId, String path) {
1701 for (DLContent dlContent : findByC_R_LikeP(companyId, repositoryId,
1702 path, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1703 remove(dlContent);
1704 }
1705 }
1706
1707
1715 @Override
1716 public int countByC_R_LikeP(long companyId, long repositoryId, String path) {
1717 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP;
1718
1719 Object[] finderArgs = new Object[] { companyId, repositoryId, path };
1720
1721 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1722 this);
1723
1724 if (count == null) {
1725 StringBundler query = new StringBundler(4);
1726
1727 query.append(_SQL_COUNT_DLCONTENT_WHERE);
1728
1729 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1730
1731 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1732
1733 boolean bindPath = false;
1734
1735 if (path == null) {
1736 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1737 }
1738 else if (path.equals(StringPool.BLANK)) {
1739 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1740 }
1741 else {
1742 bindPath = true;
1743
1744 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1745 }
1746
1747 String sql = query.toString();
1748
1749 Session session = null;
1750
1751 try {
1752 session = openSession();
1753
1754 Query q = session.createQuery(sql);
1755
1756 QueryPos qPos = QueryPos.getInstance(q);
1757
1758 qPos.add(companyId);
1759
1760 qPos.add(repositoryId);
1761
1762 if (bindPath) {
1763 qPos.add(path);
1764 }
1765
1766 count = (Long)q.uniqueResult();
1767
1768 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1769 }
1770 catch (Exception e) {
1771 FinderCacheUtil.removeResult(finderPath, finderArgs);
1772
1773 throw processException(e);
1774 }
1775 finally {
1776 closeSession(session);
1777 }
1778 }
1779
1780 return count.intValue();
1781 }
1782
1783 private static final String _FINDER_COLUMN_C_R_LIKEP_COMPANYID_2 = "dlContent.companyId = ? AND ";
1784 private static final String _FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
1785 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_1 = "dlContent.path LIKE NULL";
1786 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_2 = "dlContent.path LIKE ?";
1787 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_3 = "(dlContent.path IS NULL OR dlContent.path LIKE '')";
1788 public static final FinderPath FINDER_PATH_FETCH_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1789 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
1790 FINDER_CLASS_NAME_ENTITY, "fetchByC_R_P_V",
1791 new String[] {
1792 Long.class.getName(), Long.class.getName(),
1793 String.class.getName(), String.class.getName()
1794 },
1795 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
1796 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
1797 DLContentModelImpl.PATH_COLUMN_BITMASK |
1798 DLContentModelImpl.VERSION_COLUMN_BITMASK);
1799 public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1800 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1801 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P_V",
1802 new String[] {
1803 Long.class.getName(), Long.class.getName(),
1804 String.class.getName(), String.class.getName()
1805 });
1806
1807
1817 @Override
1818 public DLContent findByC_R_P_V(long companyId, long repositoryId,
1819 String path, String version) throws NoSuchContentException {
1820 DLContent dlContent = fetchByC_R_P_V(companyId, repositoryId, path,
1821 version);
1822
1823 if (dlContent == null) {
1824 StringBundler msg = new StringBundler(10);
1825
1826 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1827
1828 msg.append("companyId=");
1829 msg.append(companyId);
1830
1831 msg.append(", repositoryId=");
1832 msg.append(repositoryId);
1833
1834 msg.append(", path=");
1835 msg.append(path);
1836
1837 msg.append(", version=");
1838 msg.append(version);
1839
1840 msg.append(StringPool.CLOSE_CURLY_BRACE);
1841
1842 if (_log.isWarnEnabled()) {
1843 _log.warn(msg.toString());
1844 }
1845
1846 throw new NoSuchContentException(msg.toString());
1847 }
1848
1849 return dlContent;
1850 }
1851
1852
1861 @Override
1862 public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
1863 String path, String version) {
1864 return fetchByC_R_P_V(companyId, repositoryId, path, version, true);
1865 }
1866
1867
1877 @Override
1878 public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
1879 String path, String version, boolean retrieveFromCache) {
1880 Object[] finderArgs = new Object[] {
1881 companyId, repositoryId, path, version
1882 };
1883
1884 Object result = null;
1885
1886 if (retrieveFromCache) {
1887 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1888 finderArgs, this);
1889 }
1890
1891 if (result instanceof DLContent) {
1892 DLContent dlContent = (DLContent)result;
1893
1894 if ((companyId != dlContent.getCompanyId()) ||
1895 (repositoryId != dlContent.getRepositoryId()) ||
1896 !Validator.equals(path, dlContent.getPath()) ||
1897 !Validator.equals(version, dlContent.getVersion())) {
1898 result = null;
1899 }
1900 }
1901
1902 if (result == null) {
1903 StringBundler query = new StringBundler(6);
1904
1905 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1906
1907 query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
1908
1909 query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
1910
1911 boolean bindPath = false;
1912
1913 if (path == null) {
1914 query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
1915 }
1916 else if (path.equals(StringPool.BLANK)) {
1917 query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
1918 }
1919 else {
1920 bindPath = true;
1921
1922 query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
1923 }
1924
1925 boolean bindVersion = false;
1926
1927 if (version == null) {
1928 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
1929 }
1930 else if (version.equals(StringPool.BLANK)) {
1931 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
1932 }
1933 else {
1934 bindVersion = true;
1935
1936 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
1937 }
1938
1939 String sql = query.toString();
1940
1941 Session session = null;
1942
1943 try {
1944 session = openSession();
1945
1946 Query q = session.createQuery(sql);
1947
1948 QueryPos qPos = QueryPos.getInstance(q);
1949
1950 qPos.add(companyId);
1951
1952 qPos.add(repositoryId);
1953
1954 if (bindPath) {
1955 qPos.add(path);
1956 }
1957
1958 if (bindVersion) {
1959 qPos.add(version);
1960 }
1961
1962 List<DLContent> list = q.list();
1963
1964 if (list.isEmpty()) {
1965 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1966 finderArgs, list);
1967 }
1968 else {
1969 DLContent dlContent = list.get(0);
1970
1971 result = dlContent;
1972
1973 cacheResult(dlContent);
1974
1975 if ((dlContent.getCompanyId() != companyId) ||
1976 (dlContent.getRepositoryId() != repositoryId) ||
1977 (dlContent.getPath() == null) ||
1978 !dlContent.getPath().equals(path) ||
1979 (dlContent.getVersion() == null) ||
1980 !dlContent.getVersion().equals(version)) {
1981 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1982 finderArgs, dlContent);
1983 }
1984 }
1985 }
1986 catch (Exception e) {
1987 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1988 finderArgs);
1989
1990 throw processException(e);
1991 }
1992 finally {
1993 closeSession(session);
1994 }
1995 }
1996
1997 if (result instanceof List<?>) {
1998 return null;
1999 }
2000 else {
2001 return (DLContent)result;
2002 }
2003 }
2004
2005
2014 @Override
2015 public DLContent removeByC_R_P_V(long companyId, long repositoryId,
2016 String path, String version) throws NoSuchContentException {
2017 DLContent dlContent = findByC_R_P_V(companyId, repositoryId, path,
2018 version);
2019
2020 return remove(dlContent);
2021 }
2022
2023
2032 @Override
2033 public int countByC_R_P_V(long companyId, long repositoryId, String path,
2034 String version) {
2035 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R_P_V;
2036
2037 Object[] finderArgs = new Object[] {
2038 companyId, repositoryId, path, version
2039 };
2040
2041 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2042 this);
2043
2044 if (count == null) {
2045 StringBundler query = new StringBundler(5);
2046
2047 query.append(_SQL_COUNT_DLCONTENT_WHERE);
2048
2049 query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
2050
2051 query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
2052
2053 boolean bindPath = false;
2054
2055 if (path == null) {
2056 query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
2057 }
2058 else if (path.equals(StringPool.BLANK)) {
2059 query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
2060 }
2061 else {
2062 bindPath = true;
2063
2064 query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
2065 }
2066
2067 boolean bindVersion = false;
2068
2069 if (version == null) {
2070 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
2071 }
2072 else if (version.equals(StringPool.BLANK)) {
2073 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
2074 }
2075 else {
2076 bindVersion = true;
2077
2078 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
2079 }
2080
2081 String sql = query.toString();
2082
2083 Session session = null;
2084
2085 try {
2086 session = openSession();
2087
2088 Query q = session.createQuery(sql);
2089
2090 QueryPos qPos = QueryPos.getInstance(q);
2091
2092 qPos.add(companyId);
2093
2094 qPos.add(repositoryId);
2095
2096 if (bindPath) {
2097 qPos.add(path);
2098 }
2099
2100 if (bindVersion) {
2101 qPos.add(version);
2102 }
2103
2104 count = (Long)q.uniqueResult();
2105
2106 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2107 }
2108 catch (Exception e) {
2109 FinderCacheUtil.removeResult(finderPath, finderArgs);
2110
2111 throw processException(e);
2112 }
2113 finally {
2114 closeSession(session);
2115 }
2116 }
2117
2118 return count.intValue();
2119 }
2120
2121 private static final String _FINDER_COLUMN_C_R_P_V_COMPANYID_2 = "dlContent.companyId = ? AND ";
2122 private static final String _FINDER_COLUMN_C_R_P_V_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
2123 private static final String _FINDER_COLUMN_C_R_P_V_PATH_1 = "dlContent.path IS NULL AND ";
2124 private static final String _FINDER_COLUMN_C_R_P_V_PATH_2 = "dlContent.path = ? AND ";
2125 private static final String _FINDER_COLUMN_C_R_P_V_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = '') AND ";
2126 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_1 = "dlContent.version IS NULL";
2127 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_2 = "dlContent.version = ?";
2128 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_3 = "(dlContent.version IS NULL OR dlContent.version = '')";
2129
2130 public DLContentPersistenceImpl() {
2131 setModelClass(DLContent.class);
2132 }
2133
2134
2139 @Override
2140 public void cacheResult(DLContent dlContent) {
2141 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2142 DLContentImpl.class, dlContent.getPrimaryKey(), dlContent);
2143
2144 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2145 new Object[] {
2146 dlContent.getCompanyId(), dlContent.getRepositoryId(),
2147 dlContent.getPath(), dlContent.getVersion()
2148 }, dlContent);
2149
2150 dlContent.resetOriginalValues();
2151 }
2152
2153
2158 @Override
2159 public void cacheResult(List<DLContent> dlContents) {
2160 for (DLContent dlContent : dlContents) {
2161 if (EntityCacheUtil.getResult(
2162 DLContentModelImpl.ENTITY_CACHE_ENABLED,
2163 DLContentImpl.class, dlContent.getPrimaryKey()) == null) {
2164 cacheResult(dlContent);
2165 }
2166 else {
2167 dlContent.resetOriginalValues();
2168 }
2169 }
2170 }
2171
2172
2179 @Override
2180 public void clearCache() {
2181 EntityCacheUtil.clearCache(DLContentImpl.class);
2182
2183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2186 }
2187
2188
2195 @Override
2196 public void clearCache(DLContent dlContent) {
2197 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2198 DLContentImpl.class, dlContent.getPrimaryKey());
2199
2200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2201 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2202
2203 clearUniqueFindersCache(dlContent);
2204 }
2205
2206 @Override
2207 public void clearCache(List<DLContent> dlContents) {
2208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2210
2211 for (DLContent dlContent : dlContents) {
2212 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2213 DLContentImpl.class, dlContent.getPrimaryKey());
2214
2215 clearUniqueFindersCache(dlContent);
2216 }
2217 }
2218
2219 protected void cacheUniqueFindersCache(DLContent dlContent) {
2220 if (dlContent.isNew()) {
2221 Object[] args = new Object[] {
2222 dlContent.getCompanyId(), dlContent.getRepositoryId(),
2223 dlContent.getPath(), dlContent.getVersion()
2224 };
2225
2226 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
2227 Long.valueOf(1));
2228 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
2229 dlContent);
2230 }
2231 else {
2232 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2233
2234 if ((dlContentModelImpl.getColumnBitmask() &
2235 FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
2236 Object[] args = new Object[] {
2237 dlContent.getCompanyId(), dlContent.getRepositoryId(),
2238 dlContent.getPath(), dlContent.getVersion()
2239 };
2240
2241 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
2242 Long.valueOf(1));
2243 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
2244 dlContent);
2245 }
2246 }
2247 }
2248
2249 protected void clearUniqueFindersCache(DLContent dlContent) {
2250 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2251
2252 Object[] args = new Object[] {
2253 dlContent.getCompanyId(), dlContent.getRepositoryId(),
2254 dlContent.getPath(), dlContent.getVersion()
2255 };
2256
2257 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
2258 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
2259
2260 if ((dlContentModelImpl.getColumnBitmask() &
2261 FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
2262 args = new Object[] {
2263 dlContentModelImpl.getOriginalCompanyId(),
2264 dlContentModelImpl.getOriginalRepositoryId(),
2265 dlContentModelImpl.getOriginalPath(),
2266 dlContentModelImpl.getOriginalVersion()
2267 };
2268
2269 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
2270 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
2271 }
2272 }
2273
2274
2280 @Override
2281 public DLContent create(long contentId) {
2282 DLContent dlContent = new DLContentImpl();
2283
2284 dlContent.setNew(true);
2285 dlContent.setPrimaryKey(contentId);
2286
2287 return dlContent;
2288 }
2289
2290
2297 @Override
2298 public DLContent remove(long contentId) throws NoSuchContentException {
2299 return remove((Serializable)contentId);
2300 }
2301
2302
2309 @Override
2310 public DLContent remove(Serializable primaryKey)
2311 throws NoSuchContentException {
2312 Session session = null;
2313
2314 try {
2315 session = openSession();
2316
2317 DLContent dlContent = (DLContent)session.get(DLContentImpl.class,
2318 primaryKey);
2319
2320 if (dlContent == null) {
2321 if (_log.isWarnEnabled()) {
2322 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2323 }
2324
2325 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2326 primaryKey);
2327 }
2328
2329 return remove(dlContent);
2330 }
2331 catch (NoSuchContentException nsee) {
2332 throw nsee;
2333 }
2334 catch (Exception e) {
2335 throw processException(e);
2336 }
2337 finally {
2338 closeSession(session);
2339 }
2340 }
2341
2342 @Override
2343 protected DLContent removeImpl(DLContent dlContent) {
2344 dlContent = toUnwrappedModel(dlContent);
2345
2346 Session session = null;
2347
2348 try {
2349 session = openSession();
2350
2351 if (!session.contains(dlContent)) {
2352 dlContent = (DLContent)session.get(DLContentImpl.class,
2353 dlContent.getPrimaryKeyObj());
2354 }
2355
2356 if (dlContent != null) {
2357 session.delete(dlContent);
2358 }
2359 }
2360 catch (Exception e) {
2361 throw processException(e);
2362 }
2363 finally {
2364 closeSession(session);
2365 }
2366
2367 if (dlContent != null) {
2368 clearCache(dlContent);
2369 }
2370
2371 return dlContent;
2372 }
2373
2374 @Override
2375 public DLContent updateImpl(DLContent dlContent) {
2376 dlContent = toUnwrappedModel(dlContent);
2377
2378 boolean isNew = dlContent.isNew();
2379
2380 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2381
2382 Session session = null;
2383
2384 try {
2385 session = openSession();
2386
2387 if (dlContent.isNew()) {
2388 session.save(dlContent);
2389
2390 dlContent.setNew(false);
2391 }
2392 else {
2393 session.evict(dlContent);
2394 session.saveOrUpdate(dlContent);
2395 }
2396
2397 session.flush();
2398 session.clear();
2399 }
2400 catch (Exception e) {
2401 throw processException(e);
2402 }
2403 finally {
2404 closeSession(session);
2405 }
2406
2407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2408
2409 if (isNew || !DLContentModelImpl.COLUMN_BITMASK_ENABLED) {
2410 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2411 }
2412
2413 else {
2414 if ((dlContentModelImpl.getColumnBitmask() &
2415 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R.getColumnBitmask()) != 0) {
2416 Object[] args = new Object[] {
2417 dlContentModelImpl.getOriginalCompanyId(),
2418 dlContentModelImpl.getOriginalRepositoryId()
2419 };
2420
2421 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
2422 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
2423 args);
2424
2425 args = new Object[] {
2426 dlContentModelImpl.getCompanyId(),
2427 dlContentModelImpl.getRepositoryId()
2428 };
2429
2430 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
2431 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
2432 args);
2433 }
2434
2435 if ((dlContentModelImpl.getColumnBitmask() &
2436 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P.getColumnBitmask()) != 0) {
2437 Object[] args = new Object[] {
2438 dlContentModelImpl.getOriginalCompanyId(),
2439 dlContentModelImpl.getOriginalRepositoryId(),
2440 dlContentModelImpl.getOriginalPath()
2441 };
2442
2443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
2444 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
2445 args);
2446
2447 args = new Object[] {
2448 dlContentModelImpl.getCompanyId(),
2449 dlContentModelImpl.getRepositoryId(),
2450 dlContentModelImpl.getPath()
2451 };
2452
2453 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
2454 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
2455 args);
2456 }
2457 }
2458
2459 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2460 DLContentImpl.class, dlContent.getPrimaryKey(), dlContent, false);
2461
2462 clearUniqueFindersCache(dlContent);
2463 cacheUniqueFindersCache(dlContent);
2464
2465 dlContent.resetOriginalValues();
2466
2467 return dlContent;
2468 }
2469
2470 protected DLContent toUnwrappedModel(DLContent dlContent) {
2471 if (dlContent instanceof DLContentImpl) {
2472 return dlContent;
2473 }
2474
2475 DLContentImpl dlContentImpl = new DLContentImpl();
2476
2477 dlContentImpl.setNew(dlContent.isNew());
2478 dlContentImpl.setPrimaryKey(dlContent.getPrimaryKey());
2479
2480 dlContentImpl.setContentId(dlContent.getContentId());
2481 dlContentImpl.setGroupId(dlContent.getGroupId());
2482 dlContentImpl.setCompanyId(dlContent.getCompanyId());
2483 dlContentImpl.setRepositoryId(dlContent.getRepositoryId());
2484 dlContentImpl.setPath(dlContent.getPath());
2485 dlContentImpl.setVersion(dlContent.getVersion());
2486 dlContentImpl.setData(dlContent.getData());
2487 dlContentImpl.setSize(dlContent.getSize());
2488
2489 return dlContentImpl;
2490 }
2491
2492
2499 @Override
2500 public DLContent findByPrimaryKey(Serializable primaryKey)
2501 throws NoSuchContentException {
2502 DLContent dlContent = fetchByPrimaryKey(primaryKey);
2503
2504 if (dlContent == null) {
2505 if (_log.isWarnEnabled()) {
2506 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2507 }
2508
2509 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2510 primaryKey);
2511 }
2512
2513 return dlContent;
2514 }
2515
2516
2523 @Override
2524 public DLContent findByPrimaryKey(long contentId)
2525 throws NoSuchContentException {
2526 return findByPrimaryKey((Serializable)contentId);
2527 }
2528
2529
2535 @Override
2536 public DLContent fetchByPrimaryKey(Serializable primaryKey) {
2537 DLContent dlContent = (DLContent)EntityCacheUtil.getResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2538 DLContentImpl.class, primaryKey);
2539
2540 if (dlContent == _nullDLContent) {
2541 return null;
2542 }
2543
2544 if (dlContent == null) {
2545 Session session = null;
2546
2547 try {
2548 session = openSession();
2549
2550 dlContent = (DLContent)session.get(DLContentImpl.class,
2551 primaryKey);
2552
2553 if (dlContent != null) {
2554 cacheResult(dlContent);
2555 }
2556 else {
2557 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2558 DLContentImpl.class, primaryKey, _nullDLContent);
2559 }
2560 }
2561 catch (Exception e) {
2562 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2563 DLContentImpl.class, primaryKey);
2564
2565 throw processException(e);
2566 }
2567 finally {
2568 closeSession(session);
2569 }
2570 }
2571
2572 return dlContent;
2573 }
2574
2575
2581 @Override
2582 public DLContent fetchByPrimaryKey(long contentId) {
2583 return fetchByPrimaryKey((Serializable)contentId);
2584 }
2585
2586 @Override
2587 public Map<Serializable, DLContent> fetchByPrimaryKeys(
2588 Set<Serializable> primaryKeys) {
2589 if (primaryKeys.isEmpty()) {
2590 return Collections.emptyMap();
2591 }
2592
2593 Map<Serializable, DLContent> map = new HashMap<Serializable, DLContent>();
2594
2595 if (primaryKeys.size() == 1) {
2596 Iterator<Serializable> iterator = primaryKeys.iterator();
2597
2598 Serializable primaryKey = iterator.next();
2599
2600 DLContent dlContent = fetchByPrimaryKey(primaryKey);
2601
2602 if (dlContent != null) {
2603 map.put(primaryKey, dlContent);
2604 }
2605
2606 return map;
2607 }
2608
2609 Set<Serializable> uncachedPrimaryKeys = null;
2610
2611 for (Serializable primaryKey : primaryKeys) {
2612 DLContent dlContent = (DLContent)EntityCacheUtil.getResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2613 DLContentImpl.class, primaryKey);
2614
2615 if (dlContent == null) {
2616 if (uncachedPrimaryKeys == null) {
2617 uncachedPrimaryKeys = new HashSet<Serializable>();
2618 }
2619
2620 uncachedPrimaryKeys.add(primaryKey);
2621 }
2622 else {
2623 map.put(primaryKey, dlContent);
2624 }
2625 }
2626
2627 if (uncachedPrimaryKeys == null) {
2628 return map;
2629 }
2630
2631 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2632 1);
2633
2634 query.append(_SQL_SELECT_DLCONTENT_WHERE_PKS_IN);
2635
2636 for (Serializable primaryKey : uncachedPrimaryKeys) {
2637 query.append(String.valueOf(primaryKey));
2638
2639 query.append(StringPool.COMMA);
2640 }
2641
2642 query.setIndex(query.index() - 1);
2643
2644 query.append(StringPool.CLOSE_PARENTHESIS);
2645
2646 String sql = query.toString();
2647
2648 Session session = null;
2649
2650 try {
2651 session = openSession();
2652
2653 Query q = session.createQuery(sql);
2654
2655 for (DLContent dlContent : (List<DLContent>)q.list()) {
2656 map.put(dlContent.getPrimaryKeyObj(), dlContent);
2657
2658 cacheResult(dlContent);
2659
2660 uncachedPrimaryKeys.remove(dlContent.getPrimaryKeyObj());
2661 }
2662
2663 for (Serializable primaryKey : uncachedPrimaryKeys) {
2664 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2665 DLContentImpl.class, primaryKey, _nullDLContent);
2666 }
2667 }
2668 catch (Exception e) {
2669 throw processException(e);
2670 }
2671 finally {
2672 closeSession(session);
2673 }
2674
2675 return map;
2676 }
2677
2678
2683 @Override
2684 public List<DLContent> findAll() {
2685 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2686 }
2687
2688
2699 @Override
2700 public List<DLContent> findAll(int start, int end) {
2701 return findAll(start, end, null);
2702 }
2703
2704
2716 @Override
2717 public List<DLContent> findAll(int start, int end,
2718 OrderByComparator<DLContent> orderByComparator) {
2719 boolean pagination = true;
2720 FinderPath finderPath = null;
2721 Object[] finderArgs = null;
2722
2723 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2724 (orderByComparator == null)) {
2725 pagination = false;
2726 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2727 finderArgs = FINDER_ARGS_EMPTY;
2728 }
2729 else {
2730 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2731 finderArgs = new Object[] { start, end, orderByComparator };
2732 }
2733
2734 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
2735 finderArgs, this);
2736
2737 if (list == null) {
2738 StringBundler query = null;
2739 String sql = null;
2740
2741 if (orderByComparator != null) {
2742 query = new StringBundler(2 +
2743 (orderByComparator.getOrderByFields().length * 3));
2744
2745 query.append(_SQL_SELECT_DLCONTENT);
2746
2747 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2748 orderByComparator);
2749
2750 sql = query.toString();
2751 }
2752 else {
2753 sql = _SQL_SELECT_DLCONTENT;
2754
2755 if (pagination) {
2756 sql = sql.concat(DLContentModelImpl.ORDER_BY_JPQL);
2757 }
2758 }
2759
2760 Session session = null;
2761
2762 try {
2763 session = openSession();
2764
2765 Query q = session.createQuery(sql);
2766
2767 if (!pagination) {
2768 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2769 start, end, false);
2770
2771 Collections.sort(list);
2772
2773 list = Collections.unmodifiableList(list);
2774 }
2775 else {
2776 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2777 start, end);
2778 }
2779
2780 cacheResult(list);
2781
2782 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2783 }
2784 catch (Exception e) {
2785 FinderCacheUtil.removeResult(finderPath, finderArgs);
2786
2787 throw processException(e);
2788 }
2789 finally {
2790 closeSession(session);
2791 }
2792 }
2793
2794 return list;
2795 }
2796
2797
2801 @Override
2802 public void removeAll() {
2803 for (DLContent dlContent : findAll()) {
2804 remove(dlContent);
2805 }
2806 }
2807
2808
2813 @Override
2814 public int countAll() {
2815 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2816 FINDER_ARGS_EMPTY, this);
2817
2818 if (count == null) {
2819 Session session = null;
2820
2821 try {
2822 session = openSession();
2823
2824 Query q = session.createQuery(_SQL_COUNT_DLCONTENT);
2825
2826 count = (Long)q.uniqueResult();
2827
2828 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2829 FINDER_ARGS_EMPTY, count);
2830 }
2831 catch (Exception e) {
2832 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2833 FINDER_ARGS_EMPTY);
2834
2835 throw processException(e);
2836 }
2837 finally {
2838 closeSession(session);
2839 }
2840 }
2841
2842 return count.intValue();
2843 }
2844
2845 @Override
2846 protected Set<String> getBadColumnNames() {
2847 return _badColumnNames;
2848 }
2849
2850
2853 public void afterPropertiesSet() {
2854 }
2855
2856 public void destroy() {
2857 EntityCacheUtil.removeCache(DLContentImpl.class.getName());
2858 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2859 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2860 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2861 }
2862
2863 private static final String _SQL_SELECT_DLCONTENT = "SELECT dlContent FROM DLContent dlContent";
2864 private static final String _SQL_SELECT_DLCONTENT_WHERE_PKS_IN = "SELECT dlContent FROM DLContent dlContent WHERE contentId IN (";
2865 private static final String _SQL_SELECT_DLCONTENT_WHERE = "SELECT dlContent FROM DLContent dlContent WHERE ";
2866 private static final String _SQL_COUNT_DLCONTENT = "SELECT COUNT(dlContent) FROM DLContent dlContent";
2867 private static final String _SQL_COUNT_DLCONTENT_WHERE = "SELECT COUNT(dlContent) FROM DLContent dlContent WHERE ";
2868 private static final String _ORDER_BY_ENTITY_ALIAS = "dlContent.";
2869 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLContent exists with the primary key ";
2870 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLContent exists with the key {";
2871 private static final Log _log = LogFactoryUtil.getLog(DLContentPersistenceImpl.class);
2872 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2873 "path", "data", "size"
2874 });
2875 private static final DLContent _nullDLContent = new DLContentImpl() {
2876 @Override
2877 public Object clone() {
2878 return this;
2879 }
2880
2881 @Override
2882 public CacheModel<DLContent> toCacheModel() {
2883 return _nullDLContentCacheModel;
2884 }
2885 };
2886
2887 private static final CacheModel<DLContent> _nullDLContentCacheModel = new CacheModel<DLContent>() {
2888 @Override
2889 public DLContent toEntityModel() {
2890 return _nullDLContent;
2891 }
2892 };
2893 }