001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.documentlibrary.NoSuchContentException;
042 import com.liferay.portlet.documentlibrary.model.DLContent;
043 import com.liferay.portlet.documentlibrary.model.impl.DLContentImpl;
044 import com.liferay.portlet.documentlibrary.model.impl.DLContentModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class DLContentPersistenceImpl extends BasePersistenceImpl<DLContent>
065 implements DLContentPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = DLContentImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
077 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
080 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
083 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
086 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R",
088 new String[] {
089 Long.class.getName(), Long.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
095 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R",
097 new String[] { Long.class.getName(), Long.class.getName() },
098 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
099 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
100 DLContentModelImpl.VERSION_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
102 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
104 new String[] { Long.class.getName(), Long.class.getName() });
105
106
114 public List<DLContent> findByC_R(long companyId, long repositoryId)
115 throws SystemException {
116 return findByC_R(companyId, repositoryId, QueryUtil.ALL_POS,
117 QueryUtil.ALL_POS, null);
118 }
119
120
134 public List<DLContent> findByC_R(long companyId, long repositoryId,
135 int start, int end) throws SystemException {
136 return findByC_R(companyId, repositoryId, start, end, null);
137 }
138
139
154 public List<DLContent> findByC_R(long companyId, long repositoryId,
155 int start, int end, OrderByComparator orderByComparator)
156 throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R;
165 finderArgs = new Object[] { companyId, repositoryId };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R;
169 finderArgs = new Object[] {
170 companyId, repositoryId,
171
172 start, end, orderByComparator
173 };
174 }
175
176 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (DLContent dlContent : list) {
181 if ((companyId != dlContent.getCompanyId()) ||
182 (repositoryId != dlContent.getRepositoryId())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(4 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(4);
199 }
200
201 query.append(_SQL_SELECT_DLCONTENT_WHERE);
202
203 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
204
205 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(DLContentModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 qPos.add(companyId);
228
229 qPos.add(repositoryId);
230
231 if (!pagination) {
232 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
233 start, end, false);
234
235 Collections.sort(list);
236
237 list = new UnmodifiableList<DLContent>(list);
238 }
239 else {
240 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
241 start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
271 public DLContent findByC_R_First(long companyId, long repositoryId,
272 OrderByComparator orderByComparator)
273 throws NoSuchContentException, SystemException {
274 DLContent dlContent = fetchByC_R_First(companyId, repositoryId,
275 orderByComparator);
276
277 if (dlContent != null) {
278 return dlContent;
279 }
280
281 StringBundler msg = new StringBundler(6);
282
283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
284
285 msg.append("companyId=");
286 msg.append(companyId);
287
288 msg.append(", repositoryId=");
289 msg.append(repositoryId);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchContentException(msg.toString());
294 }
295
296
305 public DLContent fetchByC_R_First(long companyId, long repositoryId,
306 OrderByComparator orderByComparator) throws SystemException {
307 List<DLContent> list = findByC_R(companyId, repositoryId, 0, 1,
308 orderByComparator);
309
310 if (!list.isEmpty()) {
311 return list.get(0);
312 }
313
314 return null;
315 }
316
317
327 public DLContent findByC_R_Last(long companyId, long repositoryId,
328 OrderByComparator orderByComparator)
329 throws NoSuchContentException, SystemException {
330 DLContent dlContent = fetchByC_R_Last(companyId, repositoryId,
331 orderByComparator);
332
333 if (dlContent != null) {
334 return dlContent;
335 }
336
337 StringBundler msg = new StringBundler(6);
338
339 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340
341 msg.append("companyId=");
342 msg.append(companyId);
343
344 msg.append(", repositoryId=");
345 msg.append(repositoryId);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchContentException(msg.toString());
350 }
351
352
361 public DLContent fetchByC_R_Last(long companyId, long repositoryId,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByC_R(companyId, repositoryId);
364
365 List<DLContent> list = findByC_R(companyId, repositoryId, count - 1,
366 count, orderByComparator);
367
368 if (!list.isEmpty()) {
369 return list.get(0);
370 }
371
372 return null;
373 }
374
375
386 public DLContent[] findByC_R_PrevAndNext(long contentId, long companyId,
387 long repositoryId, OrderByComparator orderByComparator)
388 throws NoSuchContentException, SystemException {
389 DLContent dlContent = findByPrimaryKey(contentId);
390
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 DLContent[] array = new DLContentImpl[3];
397
398 array[0] = getByC_R_PrevAndNext(session, dlContent, companyId,
399 repositoryId, orderByComparator, true);
400
401 array[1] = dlContent;
402
403 array[2] = getByC_R_PrevAndNext(session, dlContent, companyId,
404 repositoryId, orderByComparator, false);
405
406 return array;
407 }
408 catch (Exception e) {
409 throw processException(e);
410 }
411 finally {
412 closeSession(session);
413 }
414 }
415
416 protected DLContent getByC_R_PrevAndNext(Session session,
417 DLContent dlContent, long companyId, long repositoryId,
418 OrderByComparator orderByComparator, boolean previous) {
419 StringBundler query = null;
420
421 if (orderByComparator != null) {
422 query = new StringBundler(6 +
423 (orderByComparator.getOrderByFields().length * 6));
424 }
425 else {
426 query = new StringBundler(3);
427 }
428
429 query.append(_SQL_SELECT_DLCONTENT_WHERE);
430
431 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
432
433 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
434
435 if (orderByComparator != null) {
436 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437
438 if (orderByConditionFields.length > 0) {
439 query.append(WHERE_AND);
440 }
441
442 for (int i = 0; i < orderByConditionFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByConditionFields[i]);
445
446 if ((i + 1) < orderByConditionFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(WHERE_GREATER_THAN_HAS_NEXT);
449 }
450 else {
451 query.append(WHERE_LESSER_THAN_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN);
460 }
461 }
462 }
463
464 query.append(ORDER_BY_CLAUSE);
465
466 String[] orderByFields = orderByComparator.getOrderByFields();
467
468 for (int i = 0; i < orderByFields.length; i++) {
469 query.append(_ORDER_BY_ENTITY_ALIAS);
470 query.append(orderByFields[i]);
471
472 if ((i + 1) < orderByFields.length) {
473 if (orderByComparator.isAscending() ^ previous) {
474 query.append(ORDER_BY_ASC_HAS_NEXT);
475 }
476 else {
477 query.append(ORDER_BY_DESC_HAS_NEXT);
478 }
479 }
480 else {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC);
483 }
484 else {
485 query.append(ORDER_BY_DESC);
486 }
487 }
488 }
489 }
490 else {
491 query.append(DLContentModelImpl.ORDER_BY_JPQL);
492 }
493
494 String sql = query.toString();
495
496 Query q = session.createQuery(sql);
497
498 q.setFirstResult(0);
499 q.setMaxResults(2);
500
501 QueryPos qPos = QueryPos.getInstance(q);
502
503 qPos.add(companyId);
504
505 qPos.add(repositoryId);
506
507 if (orderByComparator != null) {
508 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
509
510 for (Object value : values) {
511 qPos.add(value);
512 }
513 }
514
515 List<DLContent> list = q.list();
516
517 if (list.size() == 2) {
518 return list.get(1);
519 }
520 else {
521 return null;
522 }
523 }
524
525
532 public void removeByC_R(long companyId, long repositoryId)
533 throws SystemException {
534 for (DLContent dlContent : findByC_R(companyId, repositoryId,
535 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
536 remove(dlContent);
537 }
538 }
539
540
548 public int countByC_R(long companyId, long repositoryId)
549 throws SystemException {
550 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R;
551
552 Object[] finderArgs = new Object[] { companyId, repositoryId };
553
554 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
555 this);
556
557 if (count == null) {
558 StringBundler query = new StringBundler(3);
559
560 query.append(_SQL_COUNT_DLCONTENT_WHERE);
561
562 query.append(_FINDER_COLUMN_C_R_COMPANYID_2);
563
564 query.append(_FINDER_COLUMN_C_R_REPOSITORYID_2);
565
566 String sql = query.toString();
567
568 Session session = null;
569
570 try {
571 session = openSession();
572
573 Query q = session.createQuery(sql);
574
575 QueryPos qPos = QueryPos.getInstance(q);
576
577 qPos.add(companyId);
578
579 qPos.add(repositoryId);
580
581 count = (Long)q.uniqueResult();
582
583 FinderCacheUtil.putResult(finderPath, finderArgs, count);
584 }
585 catch (Exception e) {
586 FinderCacheUtil.removeResult(finderPath, finderArgs);
587
588 throw processException(e);
589 }
590 finally {
591 closeSession(session);
592 }
593 }
594
595 return count.intValue();
596 }
597
598 private static final String _FINDER_COLUMN_C_R_COMPANYID_2 = "dlContent.companyId = ? AND ";
599 private static final String _FINDER_COLUMN_C_R_REPOSITORYID_2 = "dlContent.repositoryId = ?";
600 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
601 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
602 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_P",
603 new String[] {
604 Long.class.getName(), Long.class.getName(),
605 String.class.getName(),
606
607 Integer.class.getName(), Integer.class.getName(),
608 OrderByComparator.class.getName()
609 });
610 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
611 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
612 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_R_P",
613 new String[] {
614 Long.class.getName(), Long.class.getName(),
615 String.class.getName()
616 },
617 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
618 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
619 DLContentModelImpl.PATH_COLUMN_BITMASK |
620 DLContentModelImpl.VERSION_COLUMN_BITMASK);
621 public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
622 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P",
624 new String[] {
625 Long.class.getName(), Long.class.getName(),
626 String.class.getName()
627 });
628
629
638 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
639 String path) throws SystemException {
640 return findByC_R_P(companyId, repositoryId, path, QueryUtil.ALL_POS,
641 QueryUtil.ALL_POS, null);
642 }
643
644
659 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
660 String path, int start, int end) throws SystemException {
661 return findByC_R_P(companyId, repositoryId, path, start, end, null);
662 }
663
664
680 public List<DLContent> findByC_R_P(long companyId, long repositoryId,
681 String path, int start, int end, OrderByComparator orderByComparator)
682 throws SystemException {
683 boolean pagination = true;
684 FinderPath finderPath = null;
685 Object[] finderArgs = null;
686
687 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
688 (orderByComparator == null)) {
689 pagination = false;
690 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P;
691 finderArgs = new Object[] { companyId, repositoryId, path };
692 }
693 else {
694 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_P;
695 finderArgs = new Object[] {
696 companyId, repositoryId, path,
697
698 start, end, orderByComparator
699 };
700 }
701
702 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
703 finderArgs, this);
704
705 if ((list != null) && !list.isEmpty()) {
706 for (DLContent dlContent : list) {
707 if ((companyId != dlContent.getCompanyId()) ||
708 (repositoryId != dlContent.getRepositoryId()) ||
709 !Validator.equals(path, dlContent.getPath())) {
710 list = null;
711
712 break;
713 }
714 }
715 }
716
717 if (list == null) {
718 StringBundler query = null;
719
720 if (orderByComparator != null) {
721 query = new StringBundler(5 +
722 (orderByComparator.getOrderByFields().length * 3));
723 }
724 else {
725 query = new StringBundler(5);
726 }
727
728 query.append(_SQL_SELECT_DLCONTENT_WHERE);
729
730 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
731
732 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
733
734 if (path == null) {
735 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
736 }
737 else {
738 if (path.equals(StringPool.BLANK)) {
739 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
740 }
741 else {
742 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
743 }
744 }
745
746 if (orderByComparator != null) {
747 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
748 orderByComparator);
749 }
750 else
751 if (pagination) {
752 query.append(DLContentModelImpl.ORDER_BY_JPQL);
753 }
754
755 String sql = query.toString();
756
757 Session session = null;
758
759 try {
760 session = openSession();
761
762 Query q = session.createQuery(sql);
763
764 QueryPos qPos = QueryPos.getInstance(q);
765
766 qPos.add(companyId);
767
768 qPos.add(repositoryId);
769
770 if (path != null) {
771 qPos.add(path);
772 }
773
774 if (!pagination) {
775 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
776 start, end, false);
777
778 Collections.sort(list);
779
780 list = new UnmodifiableList<DLContent>(list);
781 }
782 else {
783 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
784 start, end);
785 }
786
787 cacheResult(list);
788
789 FinderCacheUtil.putResult(finderPath, finderArgs, list);
790 }
791 catch (Exception e) {
792 FinderCacheUtil.removeResult(finderPath, finderArgs);
793
794 throw processException(e);
795 }
796 finally {
797 closeSession(session);
798 }
799 }
800
801 return list;
802 }
803
804
815 public DLContent findByC_R_P_First(long companyId, long repositoryId,
816 String path, OrderByComparator orderByComparator)
817 throws NoSuchContentException, SystemException {
818 DLContent dlContent = fetchByC_R_P_First(companyId, repositoryId, path,
819 orderByComparator);
820
821 if (dlContent != null) {
822 return dlContent;
823 }
824
825 StringBundler msg = new StringBundler(8);
826
827 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
828
829 msg.append("companyId=");
830 msg.append(companyId);
831
832 msg.append(", repositoryId=");
833 msg.append(repositoryId);
834
835 msg.append(", path=");
836 msg.append(path);
837
838 msg.append(StringPool.CLOSE_CURLY_BRACE);
839
840 throw new NoSuchContentException(msg.toString());
841 }
842
843
853 public DLContent fetchByC_R_P_First(long companyId, long repositoryId,
854 String path, OrderByComparator orderByComparator)
855 throws SystemException {
856 List<DLContent> list = findByC_R_P(companyId, repositoryId, path, 0, 1,
857 orderByComparator);
858
859 if (!list.isEmpty()) {
860 return list.get(0);
861 }
862
863 return null;
864 }
865
866
877 public DLContent findByC_R_P_Last(long companyId, long repositoryId,
878 String path, OrderByComparator orderByComparator)
879 throws NoSuchContentException, SystemException {
880 DLContent dlContent = fetchByC_R_P_Last(companyId, repositoryId, path,
881 orderByComparator);
882
883 if (dlContent != null) {
884 return dlContent;
885 }
886
887 StringBundler msg = new StringBundler(8);
888
889 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
890
891 msg.append("companyId=");
892 msg.append(companyId);
893
894 msg.append(", repositoryId=");
895 msg.append(repositoryId);
896
897 msg.append(", path=");
898 msg.append(path);
899
900 msg.append(StringPool.CLOSE_CURLY_BRACE);
901
902 throw new NoSuchContentException(msg.toString());
903 }
904
905
915 public DLContent fetchByC_R_P_Last(long companyId, long repositoryId,
916 String path, OrderByComparator orderByComparator)
917 throws SystemException {
918 int count = countByC_R_P(companyId, repositoryId, path);
919
920 List<DLContent> list = findByC_R_P(companyId, repositoryId, path,
921 count - 1, count, orderByComparator);
922
923 if (!list.isEmpty()) {
924 return list.get(0);
925 }
926
927 return null;
928 }
929
930
942 public DLContent[] findByC_R_P_PrevAndNext(long contentId, long companyId,
943 long repositoryId, String path, OrderByComparator orderByComparator)
944 throws NoSuchContentException, SystemException {
945 DLContent dlContent = findByPrimaryKey(contentId);
946
947 Session session = null;
948
949 try {
950 session = openSession();
951
952 DLContent[] array = new DLContentImpl[3];
953
954 array[0] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
955 repositoryId, path, orderByComparator, true);
956
957 array[1] = dlContent;
958
959 array[2] = getByC_R_P_PrevAndNext(session, dlContent, companyId,
960 repositoryId, path, orderByComparator, false);
961
962 return array;
963 }
964 catch (Exception e) {
965 throw processException(e);
966 }
967 finally {
968 closeSession(session);
969 }
970 }
971
972 protected DLContent getByC_R_P_PrevAndNext(Session session,
973 DLContent dlContent, long companyId, long repositoryId, String path,
974 OrderByComparator orderByComparator, boolean previous) {
975 StringBundler query = null;
976
977 if (orderByComparator != null) {
978 query = new StringBundler(6 +
979 (orderByComparator.getOrderByFields().length * 6));
980 }
981 else {
982 query = new StringBundler(3);
983 }
984
985 query.append(_SQL_SELECT_DLCONTENT_WHERE);
986
987 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
988
989 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
990
991 if (path == null) {
992 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
993 }
994 else {
995 if (path.equals(StringPool.BLANK)) {
996 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
997 }
998 else {
999 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1000 }
1001 }
1002
1003 if (orderByComparator != null) {
1004 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1005
1006 if (orderByConditionFields.length > 0) {
1007 query.append(WHERE_AND);
1008 }
1009
1010 for (int i = 0; i < orderByConditionFields.length; i++) {
1011 query.append(_ORDER_BY_ENTITY_ALIAS);
1012 query.append(orderByConditionFields[i]);
1013
1014 if ((i + 1) < orderByConditionFields.length) {
1015 if (orderByComparator.isAscending() ^ previous) {
1016 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1017 }
1018 else {
1019 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1020 }
1021 }
1022 else {
1023 if (orderByComparator.isAscending() ^ previous) {
1024 query.append(WHERE_GREATER_THAN);
1025 }
1026 else {
1027 query.append(WHERE_LESSER_THAN);
1028 }
1029 }
1030 }
1031
1032 query.append(ORDER_BY_CLAUSE);
1033
1034 String[] orderByFields = orderByComparator.getOrderByFields();
1035
1036 for (int i = 0; i < orderByFields.length; i++) {
1037 query.append(_ORDER_BY_ENTITY_ALIAS);
1038 query.append(orderByFields[i]);
1039
1040 if ((i + 1) < orderByFields.length) {
1041 if (orderByComparator.isAscending() ^ previous) {
1042 query.append(ORDER_BY_ASC_HAS_NEXT);
1043 }
1044 else {
1045 query.append(ORDER_BY_DESC_HAS_NEXT);
1046 }
1047 }
1048 else {
1049 if (orderByComparator.isAscending() ^ previous) {
1050 query.append(ORDER_BY_ASC);
1051 }
1052 else {
1053 query.append(ORDER_BY_DESC);
1054 }
1055 }
1056 }
1057 }
1058 else {
1059 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1060 }
1061
1062 String sql = query.toString();
1063
1064 Query q = session.createQuery(sql);
1065
1066 q.setFirstResult(0);
1067 q.setMaxResults(2);
1068
1069 QueryPos qPos = QueryPos.getInstance(q);
1070
1071 qPos.add(companyId);
1072
1073 qPos.add(repositoryId);
1074
1075 if (path != null) {
1076 qPos.add(path);
1077 }
1078
1079 if (orderByComparator != null) {
1080 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1081
1082 for (Object value : values) {
1083 qPos.add(value);
1084 }
1085 }
1086
1087 List<DLContent> list = q.list();
1088
1089 if (list.size() == 2) {
1090 return list.get(1);
1091 }
1092 else {
1093 return null;
1094 }
1095 }
1096
1097
1105 public void removeByC_R_P(long companyId, long repositoryId, String path)
1106 throws SystemException {
1107 for (DLContent dlContent : findByC_R_P(companyId, repositoryId, path,
1108 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1109 remove(dlContent);
1110 }
1111 }
1112
1113
1122 public int countByC_R_P(long companyId, long repositoryId, String path)
1123 throws SystemException {
1124 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R_P;
1125
1126 Object[] finderArgs = new Object[] { companyId, repositoryId, path };
1127
1128 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1129 this);
1130
1131 if (count == null) {
1132 StringBundler query = new StringBundler(4);
1133
1134 query.append(_SQL_COUNT_DLCONTENT_WHERE);
1135
1136 query.append(_FINDER_COLUMN_C_R_P_COMPANYID_2);
1137
1138 query.append(_FINDER_COLUMN_C_R_P_REPOSITORYID_2);
1139
1140 if (path == null) {
1141 query.append(_FINDER_COLUMN_C_R_P_PATH_1);
1142 }
1143 else {
1144 if (path.equals(StringPool.BLANK)) {
1145 query.append(_FINDER_COLUMN_C_R_P_PATH_3);
1146 }
1147 else {
1148 query.append(_FINDER_COLUMN_C_R_P_PATH_2);
1149 }
1150 }
1151
1152 String sql = query.toString();
1153
1154 Session session = null;
1155
1156 try {
1157 session = openSession();
1158
1159 Query q = session.createQuery(sql);
1160
1161 QueryPos qPos = QueryPos.getInstance(q);
1162
1163 qPos.add(companyId);
1164
1165 qPos.add(repositoryId);
1166
1167 if (path != null) {
1168 qPos.add(path);
1169 }
1170
1171 count = (Long)q.uniqueResult();
1172
1173 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1174 }
1175 catch (Exception e) {
1176 FinderCacheUtil.removeResult(finderPath, finderArgs);
1177
1178 throw processException(e);
1179 }
1180 finally {
1181 closeSession(session);
1182 }
1183 }
1184
1185 return count.intValue();
1186 }
1187
1188 private static final String _FINDER_COLUMN_C_R_P_COMPANYID_2 = "dlContent.companyId = ? AND ";
1189 private static final String _FINDER_COLUMN_C_R_P_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
1190 private static final String _FINDER_COLUMN_C_R_P_PATH_1 = "dlContent.path IS NULL";
1191 private static final String _FINDER_COLUMN_C_R_P_PATH_2 = "dlContent.path = ?";
1192 private static final String _FINDER_COLUMN_C_R_P_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = ?)";
1193 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP =
1194 new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1195 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
1196 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_R_LikeP",
1197 new String[] {
1198 Long.class.getName(), Long.class.getName(),
1199 String.class.getName(),
1200
1201 Integer.class.getName(), Integer.class.getName(),
1202 OrderByComparator.class.getName()
1203 });
1204 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP =
1205 new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1206 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1207 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_R_LikeP",
1208 new String[] {
1209 Long.class.getName(), Long.class.getName(),
1210 String.class.getName()
1211 });
1212
1213
1222 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1223 String path) throws SystemException {
1224 return findByC_R_LikeP(companyId, repositoryId, path,
1225 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1226 }
1227
1228
1243 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1244 String path, int start, int end) throws SystemException {
1245 return findByC_R_LikeP(companyId, repositoryId, path, start, end, null);
1246 }
1247
1248
1264 public List<DLContent> findByC_R_LikeP(long companyId, long repositoryId,
1265 String path, int start, int end, OrderByComparator orderByComparator)
1266 throws SystemException {
1267 boolean pagination = true;
1268 FinderPath finderPath = null;
1269 Object[] finderArgs = null;
1270
1271 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_R_LIKEP;
1272 finderArgs = new Object[] {
1273 companyId, repositoryId, path,
1274
1275 start, end, orderByComparator
1276 };
1277
1278 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
1279 finderArgs, this);
1280
1281 if ((list != null) && !list.isEmpty()) {
1282 for (DLContent dlContent : list) {
1283 if ((companyId != dlContent.getCompanyId()) ||
1284 (repositoryId != dlContent.getRepositoryId()) ||
1285 !Validator.equals(path, dlContent.getPath())) {
1286 list = null;
1287
1288 break;
1289 }
1290 }
1291 }
1292
1293 if (list == null) {
1294 StringBundler query = null;
1295
1296 if (orderByComparator != null) {
1297 query = new StringBundler(5 +
1298 (orderByComparator.getOrderByFields().length * 3));
1299 }
1300 else {
1301 query = new StringBundler(5);
1302 }
1303
1304 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1305
1306 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1307
1308 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1309
1310 if (path == null) {
1311 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1312 }
1313 else {
1314 if (path.equals(StringPool.BLANK)) {
1315 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1316 }
1317 else {
1318 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1319 }
1320 }
1321
1322 if (orderByComparator != null) {
1323 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1324 orderByComparator);
1325 }
1326 else
1327 if (pagination) {
1328 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1329 }
1330
1331 String sql = query.toString();
1332
1333 Session session = null;
1334
1335 try {
1336 session = openSession();
1337
1338 Query q = session.createQuery(sql);
1339
1340 QueryPos qPos = QueryPos.getInstance(q);
1341
1342 qPos.add(companyId);
1343
1344 qPos.add(repositoryId);
1345
1346 if (path != null) {
1347 qPos.add(path);
1348 }
1349
1350 if (!pagination) {
1351 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
1352 start, end, false);
1353
1354 Collections.sort(list);
1355
1356 list = new UnmodifiableList<DLContent>(list);
1357 }
1358 else {
1359 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
1360 start, end);
1361 }
1362
1363 cacheResult(list);
1364
1365 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1366 }
1367 catch (Exception e) {
1368 FinderCacheUtil.removeResult(finderPath, finderArgs);
1369
1370 throw processException(e);
1371 }
1372 finally {
1373 closeSession(session);
1374 }
1375 }
1376
1377 return list;
1378 }
1379
1380
1391 public DLContent findByC_R_LikeP_First(long companyId, long repositoryId,
1392 String path, OrderByComparator orderByComparator)
1393 throws NoSuchContentException, SystemException {
1394 DLContent dlContent = fetchByC_R_LikeP_First(companyId, repositoryId,
1395 path, orderByComparator);
1396
1397 if (dlContent != null) {
1398 return dlContent;
1399 }
1400
1401 StringBundler msg = new StringBundler(8);
1402
1403 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1404
1405 msg.append("companyId=");
1406 msg.append(companyId);
1407
1408 msg.append(", repositoryId=");
1409 msg.append(repositoryId);
1410
1411 msg.append(", path=");
1412 msg.append(path);
1413
1414 msg.append(StringPool.CLOSE_CURLY_BRACE);
1415
1416 throw new NoSuchContentException(msg.toString());
1417 }
1418
1419
1429 public DLContent fetchByC_R_LikeP_First(long companyId, long repositoryId,
1430 String path, OrderByComparator orderByComparator)
1431 throws SystemException {
1432 List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1433 0, 1, orderByComparator);
1434
1435 if (!list.isEmpty()) {
1436 return list.get(0);
1437 }
1438
1439 return null;
1440 }
1441
1442
1453 public DLContent findByC_R_LikeP_Last(long companyId, long repositoryId,
1454 String path, OrderByComparator orderByComparator)
1455 throws NoSuchContentException, SystemException {
1456 DLContent dlContent = fetchByC_R_LikeP_Last(companyId, repositoryId,
1457 path, orderByComparator);
1458
1459 if (dlContent != null) {
1460 return dlContent;
1461 }
1462
1463 StringBundler msg = new StringBundler(8);
1464
1465 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1466
1467 msg.append("companyId=");
1468 msg.append(companyId);
1469
1470 msg.append(", repositoryId=");
1471 msg.append(repositoryId);
1472
1473 msg.append(", path=");
1474 msg.append(path);
1475
1476 msg.append(StringPool.CLOSE_CURLY_BRACE);
1477
1478 throw new NoSuchContentException(msg.toString());
1479 }
1480
1481
1491 public DLContent fetchByC_R_LikeP_Last(long companyId, long repositoryId,
1492 String path, OrderByComparator orderByComparator)
1493 throws SystemException {
1494 int count = countByC_R_LikeP(companyId, repositoryId, path);
1495
1496 List<DLContent> list = findByC_R_LikeP(companyId, repositoryId, path,
1497 count - 1, count, orderByComparator);
1498
1499 if (!list.isEmpty()) {
1500 return list.get(0);
1501 }
1502
1503 return null;
1504 }
1505
1506
1518 public DLContent[] findByC_R_LikeP_PrevAndNext(long contentId,
1519 long companyId, long repositoryId, String path,
1520 OrderByComparator orderByComparator)
1521 throws NoSuchContentException, SystemException {
1522 DLContent dlContent = findByPrimaryKey(contentId);
1523
1524 Session session = null;
1525
1526 try {
1527 session = openSession();
1528
1529 DLContent[] array = new DLContentImpl[3];
1530
1531 array[0] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1532 companyId, repositoryId, path, orderByComparator, true);
1533
1534 array[1] = dlContent;
1535
1536 array[2] = getByC_R_LikeP_PrevAndNext(session, dlContent,
1537 companyId, repositoryId, path, orderByComparator, false);
1538
1539 return array;
1540 }
1541 catch (Exception e) {
1542 throw processException(e);
1543 }
1544 finally {
1545 closeSession(session);
1546 }
1547 }
1548
1549 protected DLContent getByC_R_LikeP_PrevAndNext(Session session,
1550 DLContent dlContent, long companyId, long repositoryId, String path,
1551 OrderByComparator orderByComparator, boolean previous) {
1552 StringBundler query = null;
1553
1554 if (orderByComparator != null) {
1555 query = new StringBundler(6 +
1556 (orderByComparator.getOrderByFields().length * 6));
1557 }
1558 else {
1559 query = new StringBundler(3);
1560 }
1561
1562 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1563
1564 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1565
1566 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1567
1568 if (path == null) {
1569 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1570 }
1571 else {
1572 if (path.equals(StringPool.BLANK)) {
1573 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1574 }
1575 else {
1576 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1577 }
1578 }
1579
1580 if (orderByComparator != null) {
1581 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1582
1583 if (orderByConditionFields.length > 0) {
1584 query.append(WHERE_AND);
1585 }
1586
1587 for (int i = 0; i < orderByConditionFields.length; i++) {
1588 query.append(_ORDER_BY_ENTITY_ALIAS);
1589 query.append(orderByConditionFields[i]);
1590
1591 if ((i + 1) < orderByConditionFields.length) {
1592 if (orderByComparator.isAscending() ^ previous) {
1593 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1594 }
1595 else {
1596 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1597 }
1598 }
1599 else {
1600 if (orderByComparator.isAscending() ^ previous) {
1601 query.append(WHERE_GREATER_THAN);
1602 }
1603 else {
1604 query.append(WHERE_LESSER_THAN);
1605 }
1606 }
1607 }
1608
1609 query.append(ORDER_BY_CLAUSE);
1610
1611 String[] orderByFields = orderByComparator.getOrderByFields();
1612
1613 for (int i = 0; i < orderByFields.length; i++) {
1614 query.append(_ORDER_BY_ENTITY_ALIAS);
1615 query.append(orderByFields[i]);
1616
1617 if ((i + 1) < orderByFields.length) {
1618 if (orderByComparator.isAscending() ^ previous) {
1619 query.append(ORDER_BY_ASC_HAS_NEXT);
1620 }
1621 else {
1622 query.append(ORDER_BY_DESC_HAS_NEXT);
1623 }
1624 }
1625 else {
1626 if (orderByComparator.isAscending() ^ previous) {
1627 query.append(ORDER_BY_ASC);
1628 }
1629 else {
1630 query.append(ORDER_BY_DESC);
1631 }
1632 }
1633 }
1634 }
1635 else {
1636 query.append(DLContentModelImpl.ORDER_BY_JPQL);
1637 }
1638
1639 String sql = query.toString();
1640
1641 Query q = session.createQuery(sql);
1642
1643 q.setFirstResult(0);
1644 q.setMaxResults(2);
1645
1646 QueryPos qPos = QueryPos.getInstance(q);
1647
1648 qPos.add(companyId);
1649
1650 qPos.add(repositoryId);
1651
1652 if (path != null) {
1653 qPos.add(path);
1654 }
1655
1656 if (orderByComparator != null) {
1657 Object[] values = orderByComparator.getOrderByConditionValues(dlContent);
1658
1659 for (Object value : values) {
1660 qPos.add(value);
1661 }
1662 }
1663
1664 List<DLContent> list = q.list();
1665
1666 if (list.size() == 2) {
1667 return list.get(1);
1668 }
1669 else {
1670 return null;
1671 }
1672 }
1673
1674
1682 public void removeByC_R_LikeP(long companyId, long repositoryId, String path)
1683 throws SystemException {
1684 for (DLContent dlContent : findByC_R_LikeP(companyId, repositoryId,
1685 path, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1686 remove(dlContent);
1687 }
1688 }
1689
1690
1699 public int countByC_R_LikeP(long companyId, long repositoryId, String path)
1700 throws SystemException {
1701 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_R_LIKEP;
1702
1703 Object[] finderArgs = new Object[] { companyId, repositoryId, path };
1704
1705 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1706 this);
1707
1708 if (count == null) {
1709 StringBundler query = new StringBundler(4);
1710
1711 query.append(_SQL_COUNT_DLCONTENT_WHERE);
1712
1713 query.append(_FINDER_COLUMN_C_R_LIKEP_COMPANYID_2);
1714
1715 query.append(_FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2);
1716
1717 if (path == null) {
1718 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_1);
1719 }
1720 else {
1721 if (path.equals(StringPool.BLANK)) {
1722 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_3);
1723 }
1724 else {
1725 query.append(_FINDER_COLUMN_C_R_LIKEP_PATH_2);
1726 }
1727 }
1728
1729 String sql = query.toString();
1730
1731 Session session = null;
1732
1733 try {
1734 session = openSession();
1735
1736 Query q = session.createQuery(sql);
1737
1738 QueryPos qPos = QueryPos.getInstance(q);
1739
1740 qPos.add(companyId);
1741
1742 qPos.add(repositoryId);
1743
1744 if (path != null) {
1745 qPos.add(path);
1746 }
1747
1748 count = (Long)q.uniqueResult();
1749
1750 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1751 }
1752 catch (Exception e) {
1753 FinderCacheUtil.removeResult(finderPath, finderArgs);
1754
1755 throw processException(e);
1756 }
1757 finally {
1758 closeSession(session);
1759 }
1760 }
1761
1762 return count.intValue();
1763 }
1764
1765 private static final String _FINDER_COLUMN_C_R_LIKEP_COMPANYID_2 = "dlContent.companyId = ? AND ";
1766 private static final String _FINDER_COLUMN_C_R_LIKEP_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
1767 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_1 = "dlContent.path LIKE NULL";
1768 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_2 = "dlContent.path LIKE ?";
1769 private static final String _FINDER_COLUMN_C_R_LIKEP_PATH_3 = "(dlContent.path IS NULL OR dlContent.path LIKE ?)";
1770 public static final FinderPath FINDER_PATH_FETCH_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1771 DLContentModelImpl.FINDER_CACHE_ENABLED, DLContentImpl.class,
1772 FINDER_CLASS_NAME_ENTITY, "fetchByC_R_P_V",
1773 new String[] {
1774 Long.class.getName(), Long.class.getName(),
1775 String.class.getName(), String.class.getName()
1776 },
1777 DLContentModelImpl.COMPANYID_COLUMN_BITMASK |
1778 DLContentModelImpl.REPOSITORYID_COLUMN_BITMASK |
1779 DLContentModelImpl.PATH_COLUMN_BITMASK |
1780 DLContentModelImpl.VERSION_COLUMN_BITMASK);
1781 public static final FinderPath FINDER_PATH_COUNT_BY_C_R_P_V = new FinderPath(DLContentModelImpl.ENTITY_CACHE_ENABLED,
1782 DLContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
1783 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R_P_V",
1784 new String[] {
1785 Long.class.getName(), Long.class.getName(),
1786 String.class.getName(), String.class.getName()
1787 });
1788
1789
1800 public DLContent findByC_R_P_V(long companyId, long repositoryId,
1801 String path, String version)
1802 throws NoSuchContentException, SystemException {
1803 DLContent dlContent = fetchByC_R_P_V(companyId, repositoryId, path,
1804 version);
1805
1806 if (dlContent == null) {
1807 StringBundler msg = new StringBundler(10);
1808
1809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1810
1811 msg.append("companyId=");
1812 msg.append(companyId);
1813
1814 msg.append(", repositoryId=");
1815 msg.append(repositoryId);
1816
1817 msg.append(", path=");
1818 msg.append(path);
1819
1820 msg.append(", version=");
1821 msg.append(version);
1822
1823 msg.append(StringPool.CLOSE_CURLY_BRACE);
1824
1825 if (_log.isWarnEnabled()) {
1826 _log.warn(msg.toString());
1827 }
1828
1829 throw new NoSuchContentException(msg.toString());
1830 }
1831
1832 return dlContent;
1833 }
1834
1835
1845 public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
1846 String path, String version) throws SystemException {
1847 return fetchByC_R_P_V(companyId, repositoryId, path, version, true);
1848 }
1849
1850
1861 public DLContent fetchByC_R_P_V(long companyId, long repositoryId,
1862 String path, String version, boolean retrieveFromCache)
1863 throws SystemException {
1864 Object[] finderArgs = new Object[] {
1865 companyId, repositoryId, path, version
1866 };
1867
1868 Object result = null;
1869
1870 if (retrieveFromCache) {
1871 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1872 finderArgs, this);
1873 }
1874
1875 if (result instanceof DLContent) {
1876 DLContent dlContent = (DLContent)result;
1877
1878 if ((companyId != dlContent.getCompanyId()) ||
1879 (repositoryId != dlContent.getRepositoryId()) ||
1880 !Validator.equals(path, dlContent.getPath()) ||
1881 !Validator.equals(version, dlContent.getVersion())) {
1882 result = null;
1883 }
1884 }
1885
1886 if (result == null) {
1887 StringBundler query = new StringBundler(6);
1888
1889 query.append(_SQL_SELECT_DLCONTENT_WHERE);
1890
1891 query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
1892
1893 query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
1894
1895 if (path == null) {
1896 query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
1897 }
1898 else {
1899 if (path.equals(StringPool.BLANK)) {
1900 query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
1901 }
1902 else {
1903 query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
1904 }
1905 }
1906
1907 if (version == null) {
1908 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
1909 }
1910 else {
1911 if (version.equals(StringPool.BLANK)) {
1912 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
1913 }
1914 else {
1915 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
1916 }
1917 }
1918
1919 String sql = query.toString();
1920
1921 Session session = null;
1922
1923 try {
1924 session = openSession();
1925
1926 Query q = session.createQuery(sql);
1927
1928 QueryPos qPos = QueryPos.getInstance(q);
1929
1930 qPos.add(companyId);
1931
1932 qPos.add(repositoryId);
1933
1934 if (path != null) {
1935 qPos.add(path);
1936 }
1937
1938 if (version != null) {
1939 qPos.add(version);
1940 }
1941
1942 List<DLContent> list = q.list();
1943
1944 if (list.isEmpty()) {
1945 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1946 finderArgs, list);
1947 }
1948 else {
1949 DLContent dlContent = list.get(0);
1950
1951 result = dlContent;
1952
1953 cacheResult(dlContent);
1954
1955 if ((dlContent.getCompanyId() != companyId) ||
1956 (dlContent.getRepositoryId() != repositoryId) ||
1957 (dlContent.getPath() == null) ||
1958 !dlContent.getPath().equals(path) ||
1959 (dlContent.getVersion() == null) ||
1960 !dlContent.getVersion().equals(version)) {
1961 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1962 finderArgs, dlContent);
1963 }
1964 }
1965 }
1966 catch (Exception e) {
1967 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V,
1968 finderArgs);
1969
1970 throw processException(e);
1971 }
1972 finally {
1973 closeSession(session);
1974 }
1975 }
1976
1977 if (result instanceof List<?>) {
1978 return null;
1979 }
1980 else {
1981 return (DLContent)result;
1982 }
1983 }
1984
1985
1995 public DLContent removeByC_R_P_V(long companyId, long repositoryId,
1996 String path, String version)
1997 throws NoSuchContentException, SystemException {
1998 DLContent dlContent = findByC_R_P_V(companyId, repositoryId, path,
1999 version);
2000
2001 return remove(dlContent);
2002 }
2003
2004
2014 public int countByC_R_P_V(long companyId, long repositoryId, String path,
2015 String version) throws SystemException {
2016 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_R_P_V;
2017
2018 Object[] finderArgs = new Object[] {
2019 companyId, repositoryId, path, version
2020 };
2021
2022 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2023 this);
2024
2025 if (count == null) {
2026 StringBundler query = new StringBundler(5);
2027
2028 query.append(_SQL_COUNT_DLCONTENT_WHERE);
2029
2030 query.append(_FINDER_COLUMN_C_R_P_V_COMPANYID_2);
2031
2032 query.append(_FINDER_COLUMN_C_R_P_V_REPOSITORYID_2);
2033
2034 if (path == null) {
2035 query.append(_FINDER_COLUMN_C_R_P_V_PATH_1);
2036 }
2037 else {
2038 if (path.equals(StringPool.BLANK)) {
2039 query.append(_FINDER_COLUMN_C_R_P_V_PATH_3);
2040 }
2041 else {
2042 query.append(_FINDER_COLUMN_C_R_P_V_PATH_2);
2043 }
2044 }
2045
2046 if (version == null) {
2047 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_1);
2048 }
2049 else {
2050 if (version.equals(StringPool.BLANK)) {
2051 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_3);
2052 }
2053 else {
2054 query.append(_FINDER_COLUMN_C_R_P_V_VERSION_2);
2055 }
2056 }
2057
2058 String sql = query.toString();
2059
2060 Session session = null;
2061
2062 try {
2063 session = openSession();
2064
2065 Query q = session.createQuery(sql);
2066
2067 QueryPos qPos = QueryPos.getInstance(q);
2068
2069 qPos.add(companyId);
2070
2071 qPos.add(repositoryId);
2072
2073 if (path != null) {
2074 qPos.add(path);
2075 }
2076
2077 if (version != null) {
2078 qPos.add(version);
2079 }
2080
2081 count = (Long)q.uniqueResult();
2082
2083 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2084 }
2085 catch (Exception e) {
2086 FinderCacheUtil.removeResult(finderPath, finderArgs);
2087
2088 throw processException(e);
2089 }
2090 finally {
2091 closeSession(session);
2092 }
2093 }
2094
2095 return count.intValue();
2096 }
2097
2098 private static final String _FINDER_COLUMN_C_R_P_V_COMPANYID_2 = "dlContent.companyId = ? AND ";
2099 private static final String _FINDER_COLUMN_C_R_P_V_REPOSITORYID_2 = "dlContent.repositoryId = ? AND ";
2100 private static final String _FINDER_COLUMN_C_R_P_V_PATH_1 = "dlContent.path IS NULL AND ";
2101 private static final String _FINDER_COLUMN_C_R_P_V_PATH_2 = "dlContent.path = ? AND ";
2102 private static final String _FINDER_COLUMN_C_R_P_V_PATH_3 = "(dlContent.path IS NULL OR dlContent.path = ?) AND ";
2103 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_1 = "dlContent.version IS NULL";
2104 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_2 = "dlContent.version = ?";
2105 private static final String _FINDER_COLUMN_C_R_P_V_VERSION_3 = "(dlContent.version IS NULL OR dlContent.version = ?)";
2106
2107
2112 public void cacheResult(DLContent dlContent) {
2113 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2114 DLContentImpl.class, dlContent.getPrimaryKey(), dlContent);
2115
2116 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V,
2117 new Object[] {
2118 Long.valueOf(dlContent.getCompanyId()),
2119 Long.valueOf(dlContent.getRepositoryId()),
2120
2121 dlContent.getPath(),
2122
2123 dlContent.getVersion()
2124 }, dlContent);
2125
2126 dlContent.resetOriginalValues();
2127 }
2128
2129
2134 public void cacheResult(List<DLContent> dlContents) {
2135 for (DLContent dlContent : dlContents) {
2136 if (EntityCacheUtil.getResult(
2137 DLContentModelImpl.ENTITY_CACHE_ENABLED,
2138 DLContentImpl.class, dlContent.getPrimaryKey()) == null) {
2139 cacheResult(dlContent);
2140 }
2141 else {
2142 dlContent.resetOriginalValues();
2143 }
2144 }
2145 }
2146
2147
2154 @Override
2155 public void clearCache() {
2156 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2157 CacheRegistryUtil.clear(DLContentImpl.class.getName());
2158 }
2159
2160 EntityCacheUtil.clearCache(DLContentImpl.class.getName());
2161
2162 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2163 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2164 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2165 }
2166
2167
2174 @Override
2175 public void clearCache(DLContent dlContent) {
2176 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2177 DLContentImpl.class, dlContent.getPrimaryKey());
2178
2179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2181
2182 clearUniqueFindersCache(dlContent);
2183 }
2184
2185 @Override
2186 public void clearCache(List<DLContent> dlContents) {
2187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2189
2190 for (DLContent dlContent : dlContents) {
2191 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2192 DLContentImpl.class, dlContent.getPrimaryKey());
2193
2194 clearUniqueFindersCache(dlContent);
2195 }
2196 }
2197
2198 protected void cacheUniqueFindersCache(DLContent dlContent) {
2199 if (dlContent.isNew()) {
2200 Object[] args = new Object[] {
2201 Long.valueOf(dlContent.getCompanyId()),
2202 Long.valueOf(dlContent.getRepositoryId()),
2203
2204 dlContent.getPath(),
2205
2206 dlContent.getVersion()
2207 };
2208
2209 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
2210 Long.valueOf(1));
2211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
2212 dlContent);
2213 }
2214 else {
2215 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2216
2217 if ((dlContentModelImpl.getColumnBitmask() &
2218 FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
2219 Object[] args = new Object[] {
2220 Long.valueOf(dlContent.getCompanyId()),
2221 Long.valueOf(dlContent.getRepositoryId()),
2222
2223 dlContent.getPath(),
2224
2225 dlContent.getVersion()
2226 };
2227
2228 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R_P_V, args,
2229 Long.valueOf(1));
2230 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R_P_V, args,
2231 dlContent);
2232 }
2233 }
2234 }
2235
2236 protected void clearUniqueFindersCache(DLContent dlContent) {
2237 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2238
2239 Object[] args = new Object[] {
2240 Long.valueOf(dlContent.getCompanyId()),
2241 Long.valueOf(dlContent.getRepositoryId()),
2242
2243 dlContent.getPath(),
2244
2245 dlContent.getVersion()
2246 };
2247
2248 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
2249 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
2250
2251 if ((dlContentModelImpl.getColumnBitmask() &
2252 FINDER_PATH_FETCH_BY_C_R_P_V.getColumnBitmask()) != 0) {
2253 args = new Object[] {
2254 Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
2255 Long.valueOf(dlContentModelImpl.getOriginalRepositoryId()),
2256
2257 dlContentModelImpl.getOriginalPath(),
2258
2259 dlContentModelImpl.getOriginalVersion()
2260 };
2261
2262 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P_V, args);
2263 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R_P_V, args);
2264 }
2265 }
2266
2267
2273 public DLContent create(long contentId) {
2274 DLContent dlContent = new DLContentImpl();
2275
2276 dlContent.setNew(true);
2277 dlContent.setPrimaryKey(contentId);
2278
2279 return dlContent;
2280 }
2281
2282
2290 public DLContent remove(long contentId)
2291 throws NoSuchContentException, SystemException {
2292 return remove(Long.valueOf(contentId));
2293 }
2294
2295
2303 @Override
2304 public DLContent remove(Serializable primaryKey)
2305 throws NoSuchContentException, SystemException {
2306 Session session = null;
2307
2308 try {
2309 session = openSession();
2310
2311 DLContent dlContent = (DLContent)session.get(DLContentImpl.class,
2312 primaryKey);
2313
2314 if (dlContent == null) {
2315 if (_log.isWarnEnabled()) {
2316 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2317 }
2318
2319 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2320 primaryKey);
2321 }
2322
2323 return remove(dlContent);
2324 }
2325 catch (NoSuchContentException nsee) {
2326 throw nsee;
2327 }
2328 catch (Exception e) {
2329 throw processException(e);
2330 }
2331 finally {
2332 closeSession(session);
2333 }
2334 }
2335
2336 @Override
2337 protected DLContent removeImpl(DLContent dlContent)
2338 throws SystemException {
2339 dlContent = toUnwrappedModel(dlContent);
2340
2341 Session session = null;
2342
2343 try {
2344 session = openSession();
2345
2346 if (!session.contains(dlContent)) {
2347 dlContent = (DLContent)session.get(DLContentImpl.class,
2348 dlContent.getPrimaryKeyObj());
2349 }
2350
2351 if (dlContent != null) {
2352 session.delete(dlContent);
2353 }
2354 }
2355 catch (Exception e) {
2356 throw processException(e);
2357 }
2358 finally {
2359 closeSession(session);
2360 }
2361
2362 if (dlContent != null) {
2363 clearCache(dlContent);
2364 }
2365
2366 return dlContent;
2367 }
2368
2369 @Override
2370 public DLContent updateImpl(
2371 com.liferay.portlet.documentlibrary.model.DLContent dlContent)
2372 throws SystemException {
2373 dlContent = toUnwrappedModel(dlContent);
2374
2375 boolean isNew = dlContent.isNew();
2376
2377 DLContentModelImpl dlContentModelImpl = (DLContentModelImpl)dlContent;
2378
2379 Session session = null;
2380
2381 try {
2382 session = openSession();
2383
2384 if (dlContent.isNew()) {
2385 session.save(dlContent);
2386
2387 dlContent.setNew(false);
2388 }
2389 else {
2390 session.evict(dlContent);
2391 session.saveOrUpdate(dlContent);
2392 }
2393
2394 session.flush();
2395 session.clear();
2396 }
2397 catch (Exception e) {
2398 throw processException(e);
2399 }
2400 finally {
2401 closeSession(session);
2402 }
2403
2404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2405
2406 if (isNew || !DLContentModelImpl.COLUMN_BITMASK_ENABLED) {
2407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2408 }
2409
2410 else {
2411 if ((dlContentModelImpl.getColumnBitmask() &
2412 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R.getColumnBitmask()) != 0) {
2413 Object[] args = new Object[] {
2414 Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
2415 Long.valueOf(dlContentModelImpl.getOriginalRepositoryId())
2416 };
2417
2418 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
2419 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
2420 args);
2421
2422 args = new Object[] {
2423 Long.valueOf(dlContentModelImpl.getCompanyId()),
2424 Long.valueOf(dlContentModelImpl.getRepositoryId())
2425 };
2426
2427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
2428 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R,
2429 args);
2430 }
2431
2432 if ((dlContentModelImpl.getColumnBitmask() &
2433 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P.getColumnBitmask()) != 0) {
2434 Object[] args = new Object[] {
2435 Long.valueOf(dlContentModelImpl.getOriginalCompanyId()),
2436 Long.valueOf(dlContentModelImpl.getOriginalRepositoryId()),
2437
2438 dlContentModelImpl.getOriginalPath()
2439 };
2440
2441 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
2442 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
2443 args);
2444
2445 args = new Object[] {
2446 Long.valueOf(dlContentModelImpl.getCompanyId()),
2447 Long.valueOf(dlContentModelImpl.getRepositoryId()),
2448
2449 dlContentModelImpl.getPath()
2450 };
2451
2452 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R_P, args);
2453 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_R_P,
2454 args);
2455 }
2456 }
2457
2458 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2459 DLContentImpl.class, dlContent.getPrimaryKey(), dlContent);
2460
2461 clearUniqueFindersCache(dlContent);
2462 cacheUniqueFindersCache(dlContent);
2463
2464 dlContent.resetOriginalValues();
2465
2466 return dlContent;
2467 }
2468
2469 protected DLContent toUnwrappedModel(DLContent dlContent) {
2470 if (dlContent instanceof DLContentImpl) {
2471 return dlContent;
2472 }
2473
2474 DLContentImpl dlContentImpl = new DLContentImpl();
2475
2476 dlContentImpl.setNew(dlContent.isNew());
2477 dlContentImpl.setPrimaryKey(dlContent.getPrimaryKey());
2478
2479 dlContentImpl.setContentId(dlContent.getContentId());
2480 dlContentImpl.setGroupId(dlContent.getGroupId());
2481 dlContentImpl.setCompanyId(dlContent.getCompanyId());
2482 dlContentImpl.setRepositoryId(dlContent.getRepositoryId());
2483 dlContentImpl.setPath(dlContent.getPath());
2484 dlContentImpl.setVersion(dlContent.getVersion());
2485 dlContentImpl.setData(dlContent.getData());
2486 dlContentImpl.setSize(dlContent.getSize());
2487
2488 return dlContentImpl;
2489 }
2490
2491
2499 @Override
2500 public DLContent findByPrimaryKey(Serializable primaryKey)
2501 throws NoSuchModelException, SystemException {
2502 return findByPrimaryKey(((Long)primaryKey).longValue());
2503 }
2504
2505
2513 public DLContent findByPrimaryKey(long contentId)
2514 throws NoSuchContentException, SystemException {
2515 DLContent dlContent = fetchByPrimaryKey(contentId);
2516
2517 if (dlContent == null) {
2518 if (_log.isWarnEnabled()) {
2519 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
2520 }
2521
2522 throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2523 contentId);
2524 }
2525
2526 return dlContent;
2527 }
2528
2529
2536 @Override
2537 public DLContent fetchByPrimaryKey(Serializable primaryKey)
2538 throws SystemException {
2539 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2540 }
2541
2542
2549 public DLContent fetchByPrimaryKey(long contentId)
2550 throws SystemException {
2551 DLContent dlContent = (DLContent)EntityCacheUtil.getResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2552 DLContentImpl.class, contentId);
2553
2554 if (dlContent == _nullDLContent) {
2555 return null;
2556 }
2557
2558 if (dlContent == null) {
2559 Session session = null;
2560
2561 try {
2562 session = openSession();
2563
2564 dlContent = (DLContent)session.get(DLContentImpl.class,
2565 Long.valueOf(contentId));
2566
2567 if (dlContent != null) {
2568 cacheResult(dlContent);
2569 }
2570 else {
2571 EntityCacheUtil.putResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2572 DLContentImpl.class, contentId, _nullDLContent);
2573 }
2574 }
2575 catch (Exception e) {
2576 EntityCacheUtil.removeResult(DLContentModelImpl.ENTITY_CACHE_ENABLED,
2577 DLContentImpl.class, contentId);
2578
2579 throw processException(e);
2580 }
2581 finally {
2582 closeSession(session);
2583 }
2584 }
2585
2586 return dlContent;
2587 }
2588
2589
2595 public List<DLContent> findAll() throws SystemException {
2596 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2597 }
2598
2599
2611 public List<DLContent> findAll(int start, int end)
2612 throws SystemException {
2613 return findAll(start, end, null);
2614 }
2615
2616
2629 public List<DLContent> findAll(int start, int end,
2630 OrderByComparator orderByComparator) throws SystemException {
2631 boolean pagination = true;
2632 FinderPath finderPath = null;
2633 Object[] finderArgs = null;
2634
2635 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2636 (orderByComparator == null)) {
2637 pagination = false;
2638 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2639 finderArgs = FINDER_ARGS_EMPTY;
2640 }
2641 else {
2642 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2643 finderArgs = new Object[] { start, end, orderByComparator };
2644 }
2645
2646 List<DLContent> list = (List<DLContent>)FinderCacheUtil.getResult(finderPath,
2647 finderArgs, this);
2648
2649 if (list == null) {
2650 StringBundler query = null;
2651 String sql = null;
2652
2653 if (orderByComparator != null) {
2654 query = new StringBundler(2 +
2655 (orderByComparator.getOrderByFields().length * 3));
2656
2657 query.append(_SQL_SELECT_DLCONTENT);
2658
2659 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2660 orderByComparator);
2661
2662 sql = query.toString();
2663 }
2664 else {
2665 sql = _SQL_SELECT_DLCONTENT;
2666
2667 if (pagination) {
2668 sql = sql.concat(DLContentModelImpl.ORDER_BY_JPQL);
2669 }
2670 }
2671
2672 Session session = null;
2673
2674 try {
2675 session = openSession();
2676
2677 Query q = session.createQuery(sql);
2678
2679 if (!pagination) {
2680 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2681 start, end, false);
2682
2683 Collections.sort(list);
2684
2685 list = new UnmodifiableList<DLContent>(list);
2686 }
2687 else {
2688 list = (List<DLContent>)QueryUtil.list(q, getDialect(),
2689 start, end);
2690 }
2691
2692 cacheResult(list);
2693
2694 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2695 }
2696 catch (Exception e) {
2697 FinderCacheUtil.removeResult(finderPath, finderArgs);
2698
2699 throw processException(e);
2700 }
2701 finally {
2702 closeSession(session);
2703 }
2704 }
2705
2706 return list;
2707 }
2708
2709
2714 public void removeAll() throws SystemException {
2715 for (DLContent dlContent : findAll()) {
2716 remove(dlContent);
2717 }
2718 }
2719
2720
2726 public int countAll() throws SystemException {
2727 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2728 FINDER_ARGS_EMPTY, this);
2729
2730 if (count == null) {
2731 Session session = null;
2732
2733 try {
2734 session = openSession();
2735
2736 Query q = session.createQuery(_SQL_COUNT_DLCONTENT);
2737
2738 count = (Long)q.uniqueResult();
2739
2740 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2741 FINDER_ARGS_EMPTY, count);
2742 }
2743 catch (Exception e) {
2744 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2745 FINDER_ARGS_EMPTY);
2746
2747 throw processException(e);
2748 }
2749 finally {
2750 closeSession(session);
2751 }
2752 }
2753
2754 return count.intValue();
2755 }
2756
2757
2760 public void afterPropertiesSet() {
2761 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2762 com.liferay.portal.util.PropsUtil.get(
2763 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLContent")));
2764
2765 if (listenerClassNames.length > 0) {
2766 try {
2767 List<ModelListener<DLContent>> listenersList = new ArrayList<ModelListener<DLContent>>();
2768
2769 for (String listenerClassName : listenerClassNames) {
2770 listenersList.add((ModelListener<DLContent>)InstanceFactory.newInstance(
2771 listenerClassName));
2772 }
2773
2774 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2775 }
2776 catch (Exception e) {
2777 _log.error(e);
2778 }
2779 }
2780 }
2781
2782 public void destroy() {
2783 EntityCacheUtil.removeCache(DLContentImpl.class.getName());
2784 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2785 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2786 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2787 }
2788
2789 private static final String _SQL_SELECT_DLCONTENT = "SELECT dlContent FROM DLContent dlContent";
2790 private static final String _SQL_SELECT_DLCONTENT_WHERE = "SELECT dlContent FROM DLContent dlContent WHERE ";
2791 private static final String _SQL_COUNT_DLCONTENT = "SELECT COUNT(dlContent) FROM DLContent dlContent";
2792 private static final String _SQL_COUNT_DLCONTENT_WHERE = "SELECT COUNT(dlContent) FROM DLContent dlContent WHERE ";
2793 private static final String _ORDER_BY_ENTITY_ALIAS = "dlContent.";
2794 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLContent exists with the primary key ";
2795 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLContent exists with the key {";
2796 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2797 private static Log _log = LogFactoryUtil.getLog(DLContentPersistenceImpl.class);
2798 private static DLContent _nullDLContent = new DLContentImpl() {
2799 @Override
2800 public Object clone() {
2801 return this;
2802 }
2803
2804 @Override
2805 public CacheModel<DLContent> toCacheModel() {
2806 return _nullDLContentCacheModel;
2807 }
2808 };
2809
2810 private static CacheModel<DLContent> _nullDLContentCacheModel = new CacheModel<DLContent>() {
2811 public DLContent toEntityModel() {
2812 return _nullDLContent;
2813 }
2814 };
2815 }