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