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