001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.CalendarUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.RepositoryPersistence;
042 import com.liferay.portal.service.persistence.ResourcePersistence;
043 import com.liferay.portal.service.persistence.UserPersistence;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import com.liferay.portlet.documentlibrary.NoSuchSyncException;
047 import com.liferay.portlet.documentlibrary.model.DLSync;
048 import com.liferay.portlet.documentlibrary.model.impl.DLSyncImpl;
049 import com.liferay.portlet.documentlibrary.model.impl.DLSyncModelImpl;
050
051 import java.io.Serializable;
052
053 import java.util.ArrayList;
054 import java.util.Collections;
055 import java.util.Date;
056 import java.util.List;
057
058
070 public class DLSyncPersistenceImpl extends BasePersistenceImpl<DLSync>
071 implements DLSyncPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = DLSyncImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_FETCH_BY_FILEID = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
083 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
084 FINDER_CLASS_NAME_ENTITY, "fetchByFileId",
085 new String[] { Long.class.getName() },
086 DLSyncModelImpl.FILEID_COLUMN_BITMASK);
087 public static final FinderPath FINDER_PATH_COUNT_BY_FILEID = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
088 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileId",
090 new String[] { Long.class.getName() });
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
092 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
093 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_M_R",
094 new String[] {
095 Long.class.getName(), Date.class.getName(), Long.class.getName(),
096
097 "java.lang.Integer", "java.lang.Integer",
098 "com.liferay.portal.kernel.util.OrderByComparator"
099 });
100 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
101 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_M_R",
103 new String[] {
104 Long.class.getName(), Date.class.getName(), Long.class.getName()
105 },
106 DLSyncModelImpl.COMPANYID_COLUMN_BITMASK |
107 DLSyncModelImpl.MODIFIEDDATE_COLUMN_BITMASK |
108 DLSyncModelImpl.REPOSITORYID_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
110 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_M_R",
112 new String[] {
113 Long.class.getName(), Date.class.getName(), Long.class.getName()
114 });
115 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
116 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
117 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
118 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
119 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
121 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
122 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
123 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
124
125
130 public void cacheResult(DLSync dlSync) {
131 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
132 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
133
134 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
135 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
136
137 dlSync.resetOriginalValues();
138 }
139
140
145 public void cacheResult(List<DLSync> dlSyncs) {
146 for (DLSync dlSync : dlSyncs) {
147 if (EntityCacheUtil.getResult(
148 DLSyncModelImpl.ENTITY_CACHE_ENABLED, DLSyncImpl.class,
149 dlSync.getPrimaryKey()) == null) {
150 cacheResult(dlSync);
151 }
152 else {
153 dlSync.resetOriginalValues();
154 }
155 }
156 }
157
158
165 @Override
166 public void clearCache() {
167 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
168 CacheRegistryUtil.clear(DLSyncImpl.class.getName());
169 }
170
171 EntityCacheUtil.clearCache(DLSyncImpl.class.getName());
172
173 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
176 }
177
178
185 @Override
186 public void clearCache(DLSync dlSync) {
187 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
188 DLSyncImpl.class, dlSync.getPrimaryKey());
189
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
192
193 clearUniqueFindersCache(dlSync);
194 }
195
196 @Override
197 public void clearCache(List<DLSync> dlSyncs) {
198 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
200
201 for (DLSync dlSync : dlSyncs) {
202 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
203 DLSyncImpl.class, dlSync.getPrimaryKey());
204
205 clearUniqueFindersCache(dlSync);
206 }
207 }
208
209 protected void clearUniqueFindersCache(DLSync dlSync) {
210 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
211 new Object[] { Long.valueOf(dlSync.getFileId()) });
212 }
213
214
220 public DLSync create(long syncId) {
221 DLSync dlSync = new DLSyncImpl();
222
223 dlSync.setNew(true);
224 dlSync.setPrimaryKey(syncId);
225
226 return dlSync;
227 }
228
229
237 public DLSync remove(long syncId)
238 throws NoSuchSyncException, SystemException {
239 return remove(Long.valueOf(syncId));
240 }
241
242
250 @Override
251 public DLSync remove(Serializable primaryKey)
252 throws NoSuchSyncException, SystemException {
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 DLSync dlSync = (DLSync)session.get(DLSyncImpl.class, primaryKey);
259
260 if (dlSync == null) {
261 if (_log.isWarnEnabled()) {
262 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
263 }
264
265 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
266 primaryKey);
267 }
268
269 return remove(dlSync);
270 }
271 catch (NoSuchSyncException nsee) {
272 throw nsee;
273 }
274 catch (Exception e) {
275 throw processException(e);
276 }
277 finally {
278 closeSession(session);
279 }
280 }
281
282 @Override
283 protected DLSync removeImpl(DLSync dlSync) throws SystemException {
284 dlSync = toUnwrappedModel(dlSync);
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 BatchSessionUtil.delete(session, dlSync);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 clearCache(dlSync);
301
302 return dlSync;
303 }
304
305 @Override
306 public DLSync updateImpl(
307 com.liferay.portlet.documentlibrary.model.DLSync dlSync, boolean merge)
308 throws SystemException {
309 dlSync = toUnwrappedModel(dlSync);
310
311 boolean isNew = dlSync.isNew();
312
313 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
314
315 Session session = null;
316
317 try {
318 session = openSession();
319
320 BatchSessionUtil.update(session, dlSync, merge);
321
322 dlSync.setNew(false);
323 }
324 catch (Exception e) {
325 throw processException(e);
326 }
327 finally {
328 closeSession(session);
329 }
330
331 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
332
333 if (isNew || !DLSyncModelImpl.COLUMN_BITMASK_ENABLED) {
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
335 }
336 else {
337 if ((dlSyncModelImpl.getColumnBitmask() &
338 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_M_R.getColumnBitmask()) != 0) {
339 Object[] args = new Object[] {
340 Long.valueOf(dlSyncModelImpl.getOriginalCompanyId()),
341
342 dlSyncModelImpl.getOriginalModifiedDate(),
343 Long.valueOf(dlSyncModelImpl.getOriginalRepositoryId())
344 };
345
346 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_M_R, args);
347 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_M_R,
348 args);
349
350 args = new Object[] {
351 Long.valueOf(dlSyncModelImpl.getCompanyId()),
352
353 dlSyncModelImpl.getModifiedDate(),
354 Long.valueOf(dlSyncModelImpl.getRepositoryId())
355 };
356
357 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_M_R, args);
358 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_M_R,
359 args);
360 }
361 }
362
363 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
364 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
365
366 if (isNew) {
367 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
368 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
369 }
370 else {
371 if ((dlSyncModelImpl.getColumnBitmask() &
372 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
373 Object[] args = new Object[] {
374 Long.valueOf(dlSyncModelImpl.getOriginalFileId())
375 };
376
377 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
378 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
379
380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
381 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
382 }
383 }
384
385 return dlSync;
386 }
387
388 protected DLSync toUnwrappedModel(DLSync dlSync) {
389 if (dlSync instanceof DLSyncImpl) {
390 return dlSync;
391 }
392
393 DLSyncImpl dlSyncImpl = new DLSyncImpl();
394
395 dlSyncImpl.setNew(dlSync.isNew());
396 dlSyncImpl.setPrimaryKey(dlSync.getPrimaryKey());
397
398 dlSyncImpl.setSyncId(dlSync.getSyncId());
399 dlSyncImpl.setCompanyId(dlSync.getCompanyId());
400 dlSyncImpl.setCreateDate(dlSync.getCreateDate());
401 dlSyncImpl.setModifiedDate(dlSync.getModifiedDate());
402 dlSyncImpl.setFileId(dlSync.getFileId());
403 dlSyncImpl.setFileUuid(dlSync.getFileUuid());
404 dlSyncImpl.setRepositoryId(dlSync.getRepositoryId());
405 dlSyncImpl.setParentFolderId(dlSync.getParentFolderId());
406 dlSyncImpl.setName(dlSync.getName());
407 dlSyncImpl.setDescription(dlSync.getDescription());
408 dlSyncImpl.setEvent(dlSync.getEvent());
409 dlSyncImpl.setType(dlSync.getType());
410 dlSyncImpl.setVersion(dlSync.getVersion());
411
412 return dlSyncImpl;
413 }
414
415
423 @Override
424 public DLSync findByPrimaryKey(Serializable primaryKey)
425 throws NoSuchModelException, SystemException {
426 return findByPrimaryKey(((Long)primaryKey).longValue());
427 }
428
429
437 public DLSync findByPrimaryKey(long syncId)
438 throws NoSuchSyncException, SystemException {
439 DLSync dlSync = fetchByPrimaryKey(syncId);
440
441 if (dlSync == null) {
442 if (_log.isWarnEnabled()) {
443 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + syncId);
444 }
445
446 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
447 syncId);
448 }
449
450 return dlSync;
451 }
452
453
460 @Override
461 public DLSync fetchByPrimaryKey(Serializable primaryKey)
462 throws SystemException {
463 return fetchByPrimaryKey(((Long)primaryKey).longValue());
464 }
465
466
473 public DLSync fetchByPrimaryKey(long syncId) throws SystemException {
474 DLSync dlSync = (DLSync)EntityCacheUtil.getResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
475 DLSyncImpl.class, syncId);
476
477 if (dlSync == _nullDLSync) {
478 return null;
479 }
480
481 if (dlSync == null) {
482 Session session = null;
483
484 boolean hasException = false;
485
486 try {
487 session = openSession();
488
489 dlSync = (DLSync)session.get(DLSyncImpl.class,
490 Long.valueOf(syncId));
491 }
492 catch (Exception e) {
493 hasException = true;
494
495 throw processException(e);
496 }
497 finally {
498 if (dlSync != null) {
499 cacheResult(dlSync);
500 }
501 else if (!hasException) {
502 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
503 DLSyncImpl.class, syncId, _nullDLSync);
504 }
505
506 closeSession(session);
507 }
508 }
509
510 return dlSync;
511 }
512
513
521 public DLSync findByFileId(long fileId)
522 throws NoSuchSyncException, SystemException {
523 DLSync dlSync = fetchByFileId(fileId);
524
525 if (dlSync == null) {
526 StringBundler msg = new StringBundler(4);
527
528 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
529
530 msg.append("fileId=");
531 msg.append(fileId);
532
533 msg.append(StringPool.CLOSE_CURLY_BRACE);
534
535 if (_log.isWarnEnabled()) {
536 _log.warn(msg.toString());
537 }
538
539 throw new NoSuchSyncException(msg.toString());
540 }
541
542 return dlSync;
543 }
544
545
552 public DLSync fetchByFileId(long fileId) throws SystemException {
553 return fetchByFileId(fileId, true);
554 }
555
556
564 public DLSync fetchByFileId(long fileId, boolean retrieveFromCache)
565 throws SystemException {
566 Object[] finderArgs = new Object[] { fileId };
567
568 Object result = null;
569
570 if (retrieveFromCache) {
571 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FILEID,
572 finderArgs, this);
573 }
574
575 if (result instanceof DLSync) {
576 DLSync dlSync = (DLSync)result;
577
578 if ((fileId != dlSync.getFileId())) {
579 result = null;
580 }
581 }
582
583 if (result == null) {
584 StringBundler query = new StringBundler(3);
585
586 query.append(_SQL_SELECT_DLSYNC_WHERE);
587
588 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
589
590 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
591
592 String sql = query.toString();
593
594 Session session = null;
595
596 try {
597 session = openSession();
598
599 Query q = session.createQuery(sql);
600
601 QueryPos qPos = QueryPos.getInstance(q);
602
603 qPos.add(fileId);
604
605 List<DLSync> list = q.list();
606
607 result = list;
608
609 DLSync dlSync = null;
610
611 if (list.isEmpty()) {
612 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
613 finderArgs, list);
614 }
615 else {
616 dlSync = list.get(0);
617
618 cacheResult(dlSync);
619
620 if ((dlSync.getFileId() != fileId)) {
621 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
622 finderArgs, dlSync);
623 }
624 }
625
626 return dlSync;
627 }
628 catch (Exception e) {
629 throw processException(e);
630 }
631 finally {
632 if (result == null) {
633 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
634 finderArgs);
635 }
636
637 closeSession(session);
638 }
639 }
640 else {
641 if (result instanceof List<?>) {
642 return null;
643 }
644 else {
645 return (DLSync)result;
646 }
647 }
648 }
649
650
659 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
660 long repositoryId) throws SystemException {
661 return findByC_M_R(companyId, modifiedDate, repositoryId,
662 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
663 }
664
665
680 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
681 long repositoryId, int start, int end) throws SystemException {
682 return findByC_M_R(companyId, modifiedDate, repositoryId, start, end,
683 null);
684 }
685
686
702 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
703 long repositoryId, int start, int end,
704 OrderByComparator orderByComparator) throws SystemException {
705 FinderPath finderPath = null;
706 Object[] finderArgs = null;
707
708 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
709 (orderByComparator == null)) {
710 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_M_R;
711 finderArgs = new Object[] { companyId, modifiedDate, repositoryId };
712 }
713 else {
714 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R;
715 finderArgs = new Object[] {
716 companyId, modifiedDate, repositoryId,
717
718 start, end, orderByComparator
719 };
720 }
721
722 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
723 finderArgs, this);
724
725 if ((list != null) && !list.isEmpty()) {
726 for (DLSync dlSync : list) {
727 if ((companyId != dlSync.getCompanyId()) ||
728 !Validator.equals(modifiedDate, dlSync.getModifiedDate()) ||
729 (repositoryId != dlSync.getRepositoryId())) {
730 list = null;
731
732 break;
733 }
734 }
735 }
736
737 if (list == null) {
738 StringBundler query = null;
739
740 if (orderByComparator != null) {
741 query = new StringBundler(5 +
742 (orderByComparator.getOrderByFields().length * 3));
743 }
744 else {
745 query = new StringBundler(5);
746 }
747
748 query.append(_SQL_SELECT_DLSYNC_WHERE);
749
750 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
751
752 if (modifiedDate == null) {
753 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
754 }
755 else {
756 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
757 }
758
759 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
760
761 if (orderByComparator != null) {
762 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
763 orderByComparator);
764 }
765
766 else {
767 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
768 }
769
770 String sql = query.toString();
771
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 Query q = session.createQuery(sql);
778
779 QueryPos qPos = QueryPos.getInstance(q);
780
781 qPos.add(companyId);
782
783 if (modifiedDate != null) {
784 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
785 }
786
787 qPos.add(repositoryId);
788
789 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start, end);
790 }
791 catch (Exception e) {
792 throw processException(e);
793 }
794 finally {
795 if (list == null) {
796 FinderCacheUtil.removeResult(finderPath, finderArgs);
797 }
798 else {
799 cacheResult(list);
800
801 FinderCacheUtil.putResult(finderPath, finderArgs, list);
802 }
803
804 closeSession(session);
805 }
806 }
807
808 return list;
809 }
810
811
826 public DLSync findByC_M_R_First(long companyId, Date modifiedDate,
827 long repositoryId, OrderByComparator orderByComparator)
828 throws NoSuchSyncException, SystemException {
829 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
830 0, 1, orderByComparator);
831
832 if (list.isEmpty()) {
833 StringBundler msg = new StringBundler(8);
834
835 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
836
837 msg.append("companyId=");
838 msg.append(companyId);
839
840 msg.append(", modifiedDate=");
841 msg.append(modifiedDate);
842
843 msg.append(", repositoryId=");
844 msg.append(repositoryId);
845
846 msg.append(StringPool.CLOSE_CURLY_BRACE);
847
848 throw new NoSuchSyncException(msg.toString());
849 }
850 else {
851 return list.get(0);
852 }
853 }
854
855
870 public DLSync findByC_M_R_Last(long companyId, Date modifiedDate,
871 long repositoryId, OrderByComparator orderByComparator)
872 throws NoSuchSyncException, SystemException {
873 int count = countByC_M_R(companyId, modifiedDate, repositoryId);
874
875 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
876 count - 1, count, orderByComparator);
877
878 if (list.isEmpty()) {
879 StringBundler msg = new StringBundler(8);
880
881 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
882
883 msg.append("companyId=");
884 msg.append(companyId);
885
886 msg.append(", modifiedDate=");
887 msg.append(modifiedDate);
888
889 msg.append(", repositoryId=");
890 msg.append(repositoryId);
891
892 msg.append(StringPool.CLOSE_CURLY_BRACE);
893
894 throw new NoSuchSyncException(msg.toString());
895 }
896 else {
897 return list.get(0);
898 }
899 }
900
901
917 public DLSync[] findByC_M_R_PrevAndNext(long syncId, long companyId,
918 Date modifiedDate, long repositoryId,
919 OrderByComparator orderByComparator)
920 throws NoSuchSyncException, SystemException {
921 DLSync dlSync = findByPrimaryKey(syncId);
922
923 Session session = null;
924
925 try {
926 session = openSession();
927
928 DLSync[] array = new DLSyncImpl[3];
929
930 array[0] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
931 modifiedDate, repositoryId, orderByComparator, true);
932
933 array[1] = dlSync;
934
935 array[2] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
936 modifiedDate, repositoryId, orderByComparator, false);
937
938 return array;
939 }
940 catch (Exception e) {
941 throw processException(e);
942 }
943 finally {
944 closeSession(session);
945 }
946 }
947
948 protected DLSync getByC_M_R_PrevAndNext(Session session, DLSync dlSync,
949 long companyId, Date modifiedDate, long repositoryId,
950 OrderByComparator orderByComparator, boolean previous) {
951 StringBundler query = null;
952
953 if (orderByComparator != null) {
954 query = new StringBundler(6 +
955 (orderByComparator.getOrderByFields().length * 6));
956 }
957 else {
958 query = new StringBundler(3);
959 }
960
961 query.append(_SQL_SELECT_DLSYNC_WHERE);
962
963 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
964
965 if (modifiedDate == null) {
966 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
967 }
968 else {
969 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
970 }
971
972 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
973
974 if (orderByComparator != null) {
975 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
976
977 if (orderByConditionFields.length > 0) {
978 query.append(WHERE_AND);
979 }
980
981 for (int i = 0; i < orderByConditionFields.length; i++) {
982 query.append(_ORDER_BY_ENTITY_ALIAS);
983 query.append(orderByConditionFields[i]);
984
985 if ((i + 1) < orderByConditionFields.length) {
986 if (orderByComparator.isAscending() ^ previous) {
987 query.append(WHERE_GREATER_THAN_HAS_NEXT);
988 }
989 else {
990 query.append(WHERE_LESSER_THAN_HAS_NEXT);
991 }
992 }
993 else {
994 if (orderByComparator.isAscending() ^ previous) {
995 query.append(WHERE_GREATER_THAN);
996 }
997 else {
998 query.append(WHERE_LESSER_THAN);
999 }
1000 }
1001 }
1002
1003 query.append(ORDER_BY_CLAUSE);
1004
1005 String[] orderByFields = orderByComparator.getOrderByFields();
1006
1007 for (int i = 0; i < orderByFields.length; i++) {
1008 query.append(_ORDER_BY_ENTITY_ALIAS);
1009 query.append(orderByFields[i]);
1010
1011 if ((i + 1) < orderByFields.length) {
1012 if (orderByComparator.isAscending() ^ previous) {
1013 query.append(ORDER_BY_ASC_HAS_NEXT);
1014 }
1015 else {
1016 query.append(ORDER_BY_DESC_HAS_NEXT);
1017 }
1018 }
1019 else {
1020 if (orderByComparator.isAscending() ^ previous) {
1021 query.append(ORDER_BY_ASC);
1022 }
1023 else {
1024 query.append(ORDER_BY_DESC);
1025 }
1026 }
1027 }
1028 }
1029
1030 else {
1031 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
1032 }
1033
1034 String sql = query.toString();
1035
1036 Query q = session.createQuery(sql);
1037
1038 q.setFirstResult(0);
1039 q.setMaxResults(2);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 qPos.add(companyId);
1044
1045 if (modifiedDate != null) {
1046 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1047 }
1048
1049 qPos.add(repositoryId);
1050
1051 if (orderByComparator != null) {
1052 Object[] values = orderByComparator.getOrderByConditionValues(dlSync);
1053
1054 for (Object value : values) {
1055 qPos.add(value);
1056 }
1057 }
1058
1059 List<DLSync> list = q.list();
1060
1061 if (list.size() == 2) {
1062 return list.get(1);
1063 }
1064 else {
1065 return null;
1066 }
1067 }
1068
1069
1075 public List<DLSync> findAll() throws SystemException {
1076 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1077 }
1078
1079
1091 public List<DLSync> findAll(int start, int end) throws SystemException {
1092 return findAll(start, end, null);
1093 }
1094
1095
1108 public List<DLSync> findAll(int start, int end,
1109 OrderByComparator orderByComparator) throws SystemException {
1110 FinderPath finderPath = null;
1111 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1112
1113 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1114 (orderByComparator == null)) {
1115 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1116 finderArgs = FINDER_ARGS_EMPTY;
1117 }
1118 else {
1119 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1120 finderArgs = new Object[] { start, end, orderByComparator };
1121 }
1122
1123 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
1124 finderArgs, this);
1125
1126 if (list == null) {
1127 StringBundler query = null;
1128 String sql = null;
1129
1130 if (orderByComparator != null) {
1131 query = new StringBundler(2 +
1132 (orderByComparator.getOrderByFields().length * 3));
1133
1134 query.append(_SQL_SELECT_DLSYNC);
1135
1136 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1137 orderByComparator);
1138
1139 sql = query.toString();
1140 }
1141 else {
1142 sql = _SQL_SELECT_DLSYNC.concat(DLSyncModelImpl.ORDER_BY_JPQL);
1143 }
1144
1145 Session session = null;
1146
1147 try {
1148 session = openSession();
1149
1150 Query q = session.createQuery(sql);
1151
1152 if (orderByComparator == null) {
1153 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1154 end, false);
1155
1156 Collections.sort(list);
1157 }
1158 else {
1159 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1160 end);
1161 }
1162 }
1163 catch (Exception e) {
1164 throw processException(e);
1165 }
1166 finally {
1167 if (list == null) {
1168 FinderCacheUtil.removeResult(finderPath, finderArgs);
1169 }
1170 else {
1171 cacheResult(list);
1172
1173 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1174 }
1175
1176 closeSession(session);
1177 }
1178 }
1179
1180 return list;
1181 }
1182
1183
1189 public void removeByFileId(long fileId)
1190 throws NoSuchSyncException, SystemException {
1191 DLSync dlSync = findByFileId(fileId);
1192
1193 remove(dlSync);
1194 }
1195
1196
1204 public void removeByC_M_R(long companyId, Date modifiedDate,
1205 long repositoryId) throws SystemException {
1206 for (DLSync dlSync : findByC_M_R(companyId, modifiedDate, repositoryId)) {
1207 remove(dlSync);
1208 }
1209 }
1210
1211
1216 public void removeAll() throws SystemException {
1217 for (DLSync dlSync : findAll()) {
1218 remove(dlSync);
1219 }
1220 }
1221
1222
1229 public int countByFileId(long fileId) throws SystemException {
1230 Object[] finderArgs = new Object[] { fileId };
1231
1232 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FILEID,
1233 finderArgs, this);
1234
1235 if (count == null) {
1236 StringBundler query = new StringBundler(2);
1237
1238 query.append(_SQL_COUNT_DLSYNC_WHERE);
1239
1240 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
1241
1242 String sql = query.toString();
1243
1244 Session session = null;
1245
1246 try {
1247 session = openSession();
1248
1249 Query q = session.createQuery(sql);
1250
1251 QueryPos qPos = QueryPos.getInstance(q);
1252
1253 qPos.add(fileId);
1254
1255 count = (Long)q.uniqueResult();
1256 }
1257 catch (Exception e) {
1258 throw processException(e);
1259 }
1260 finally {
1261 if (count == null) {
1262 count = Long.valueOf(0);
1263 }
1264
1265 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID,
1266 finderArgs, count);
1267
1268 closeSession(session);
1269 }
1270 }
1271
1272 return count.intValue();
1273 }
1274
1275
1284 public int countByC_M_R(long companyId, Date modifiedDate, long repositoryId)
1285 throws SystemException {
1286 Object[] finderArgs = new Object[] { companyId, modifiedDate, repositoryId };
1287
1288 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_M_R,
1289 finderArgs, this);
1290
1291 if (count == null) {
1292 StringBundler query = new StringBundler(4);
1293
1294 query.append(_SQL_COUNT_DLSYNC_WHERE);
1295
1296 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
1297
1298 if (modifiedDate == null) {
1299 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
1300 }
1301 else {
1302 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
1303 }
1304
1305 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
1306
1307 String sql = query.toString();
1308
1309 Session session = null;
1310
1311 try {
1312 session = openSession();
1313
1314 Query q = session.createQuery(sql);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 qPos.add(companyId);
1319
1320 if (modifiedDate != null) {
1321 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1322 }
1323
1324 qPos.add(repositoryId);
1325
1326 count = (Long)q.uniqueResult();
1327 }
1328 catch (Exception e) {
1329 throw processException(e);
1330 }
1331 finally {
1332 if (count == null) {
1333 count = Long.valueOf(0);
1334 }
1335
1336 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_M_R,
1337 finderArgs, count);
1338
1339 closeSession(session);
1340 }
1341 }
1342
1343 return count.intValue();
1344 }
1345
1346
1352 public int countAll() throws SystemException {
1353 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1354 FINDER_ARGS_EMPTY, this);
1355
1356 if (count == null) {
1357 Session session = null;
1358
1359 try {
1360 session = openSession();
1361
1362 Query q = session.createQuery(_SQL_COUNT_DLSYNC);
1363
1364 count = (Long)q.uniqueResult();
1365 }
1366 catch (Exception e) {
1367 throw processException(e);
1368 }
1369 finally {
1370 if (count == null) {
1371 count = Long.valueOf(0);
1372 }
1373
1374 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1375 FINDER_ARGS_EMPTY, count);
1376
1377 closeSession(session);
1378 }
1379 }
1380
1381 return count.intValue();
1382 }
1383
1384
1387 public void afterPropertiesSet() {
1388 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1389 com.liferay.portal.util.PropsUtil.get(
1390 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSync")));
1391
1392 if (listenerClassNames.length > 0) {
1393 try {
1394 List<ModelListener<DLSync>> listenersList = new ArrayList<ModelListener<DLSync>>();
1395
1396 for (String listenerClassName : listenerClassNames) {
1397 listenersList.add((ModelListener<DLSync>)InstanceFactory.newInstance(
1398 listenerClassName));
1399 }
1400
1401 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1402 }
1403 catch (Exception e) {
1404 _log.error(e);
1405 }
1406 }
1407 }
1408
1409 public void destroy() {
1410 EntityCacheUtil.removeCache(DLSyncImpl.class.getName());
1411 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1412 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1413 }
1414
1415 @BeanReference(type = DLContentPersistence.class)
1416 protected DLContentPersistence dlContentPersistence;
1417 @BeanReference(type = DLFileEntryPersistence.class)
1418 protected DLFileEntryPersistence dlFileEntryPersistence;
1419 @BeanReference(type = DLFileEntryMetadataPersistence.class)
1420 protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
1421 @BeanReference(type = DLFileEntryTypePersistence.class)
1422 protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
1423 @BeanReference(type = DLFileRankPersistence.class)
1424 protected DLFileRankPersistence dlFileRankPersistence;
1425 @BeanReference(type = DLFileShortcutPersistence.class)
1426 protected DLFileShortcutPersistence dlFileShortcutPersistence;
1427 @BeanReference(type = DLFileVersionPersistence.class)
1428 protected DLFileVersionPersistence dlFileVersionPersistence;
1429 @BeanReference(type = DLFolderPersistence.class)
1430 protected DLFolderPersistence dlFolderPersistence;
1431 @BeanReference(type = DLSyncPersistence.class)
1432 protected DLSyncPersistence dlSyncPersistence;
1433 @BeanReference(type = RepositoryPersistence.class)
1434 protected RepositoryPersistence repositoryPersistence;
1435 @BeanReference(type = ResourcePersistence.class)
1436 protected ResourcePersistence resourcePersistence;
1437 @BeanReference(type = UserPersistence.class)
1438 protected UserPersistence userPersistence;
1439 private static final String _SQL_SELECT_DLSYNC = "SELECT dlSync FROM DLSync dlSync";
1440 private static final String _SQL_SELECT_DLSYNC_WHERE = "SELECT dlSync FROM DLSync dlSync WHERE ";
1441 private static final String _SQL_COUNT_DLSYNC = "SELECT COUNT(dlSync) FROM DLSync dlSync";
1442 private static final String _SQL_COUNT_DLSYNC_WHERE = "SELECT COUNT(dlSync) FROM DLSync dlSync WHERE ";
1443 private static final String _FINDER_COLUMN_FILEID_FILEID_2 = "dlSync.fileId = ?";
1444 private static final String _FINDER_COLUMN_C_M_R_COMPANYID_2 = "dlSync.companyId = ? AND ";
1445 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_1 = "dlSync.modifiedDate >= NULL AND ";
1446 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_2 = "dlSync.modifiedDate >= ? AND ";
1447 private static final String _FINDER_COLUMN_C_M_R_REPOSITORYID_2 = "dlSync.repositoryId = ?";
1448 private static final String _ORDER_BY_ENTITY_ALIAS = "dlSync.";
1449 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSync exists with the primary key ";
1450 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSync exists with the key {";
1451 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1452 private static Log _log = LogFactoryUtil.getLog(DLSyncPersistenceImpl.class);
1453 private static DLSync _nullDLSync = new DLSyncImpl() {
1454 @Override
1455 public Object clone() {
1456 return this;
1457 }
1458
1459 @Override
1460 public CacheModel<DLSync> toCacheModel() {
1461 return _nullDLSyncCacheModel;
1462 }
1463 };
1464
1465 private static CacheModel<DLSync> _nullDLSyncCacheModel = new CacheModel<DLSync>() {
1466 public DLSync toEntityModel() {
1467 return _nullDLSync;
1468 }
1469 };
1470 }