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_WITH_PAGINATION_COUNT_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
101 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_M_R",
103 new String[] {
104 Long.class.getName(), Date.class.getName(), Long.class.getName()
105 });
106 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
107 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
108 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
109 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
110 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
113 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
115
116
121 public void cacheResult(DLSync dlSync) {
122 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
123 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
124
125 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
126 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
127
128 dlSync.resetOriginalValues();
129 }
130
131
136 public void cacheResult(List<DLSync> dlSyncs) {
137 for (DLSync dlSync : dlSyncs) {
138 if (EntityCacheUtil.getResult(
139 DLSyncModelImpl.ENTITY_CACHE_ENABLED, DLSyncImpl.class,
140 dlSync.getPrimaryKey()) == null) {
141 cacheResult(dlSync);
142 }
143 else {
144 dlSync.resetOriginalValues();
145 }
146 }
147 }
148
149
156 @Override
157 public void clearCache() {
158 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
159 CacheRegistryUtil.clear(DLSyncImpl.class.getName());
160 }
161
162 EntityCacheUtil.clearCache(DLSyncImpl.class.getName());
163
164 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
165 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
167 }
168
169
176 @Override
177 public void clearCache(DLSync dlSync) {
178 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
179 DLSyncImpl.class, dlSync.getPrimaryKey());
180
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
183
184 clearUniqueFindersCache(dlSync);
185 }
186
187 @Override
188 public void clearCache(List<DLSync> dlSyncs) {
189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
191
192 for (DLSync dlSync : dlSyncs) {
193 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
194 DLSyncImpl.class, dlSync.getPrimaryKey());
195
196 clearUniqueFindersCache(dlSync);
197 }
198 }
199
200 protected void cacheUniqueFindersCache(DLSync dlSync) {
201 if (dlSync.isNew()) {
202 Object[] args = new Object[] { Long.valueOf(dlSync.getFileId()) };
203
204 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID, args,
205 Long.valueOf(1));
206 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID, args, dlSync);
207 }
208 else {
209 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
210
211 if ((dlSyncModelImpl.getColumnBitmask() &
212 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
213 Object[] args = new Object[] { Long.valueOf(dlSync.getFileId()) };
214
215 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID, args,
216 Long.valueOf(1));
217 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID, args,
218 dlSync);
219 }
220 }
221 }
222
223 protected void clearUniqueFindersCache(DLSync dlSync) {
224 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
225
226 Object[] args = new Object[] { Long.valueOf(dlSync.getFileId()) };
227
228 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
229 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
230
231 if ((dlSyncModelImpl.getColumnBitmask() &
232 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
233 args = new Object[] {
234 Long.valueOf(dlSyncModelImpl.getOriginalFileId())
235 };
236
237 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
238 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
239 }
240 }
241
242
248 public DLSync create(long syncId) {
249 DLSync dlSync = new DLSyncImpl();
250
251 dlSync.setNew(true);
252 dlSync.setPrimaryKey(syncId);
253
254 return dlSync;
255 }
256
257
265 public DLSync remove(long syncId)
266 throws NoSuchSyncException, SystemException {
267 return remove(Long.valueOf(syncId));
268 }
269
270
278 @Override
279 public DLSync remove(Serializable primaryKey)
280 throws NoSuchSyncException, SystemException {
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 DLSync dlSync = (DLSync)session.get(DLSyncImpl.class, primaryKey);
287
288 if (dlSync == null) {
289 if (_log.isWarnEnabled()) {
290 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
291 }
292
293 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
294 primaryKey);
295 }
296
297 return remove(dlSync);
298 }
299 catch (NoSuchSyncException nsee) {
300 throw nsee;
301 }
302 catch (Exception e) {
303 throw processException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308 }
309
310 @Override
311 protected DLSync removeImpl(DLSync dlSync) throws SystemException {
312 dlSync = toUnwrappedModel(dlSync);
313
314 Session session = null;
315
316 try {
317 session = openSession();
318
319 BatchSessionUtil.delete(session, dlSync);
320 }
321 catch (Exception e) {
322 throw processException(e);
323 }
324 finally {
325 closeSession(session);
326 }
327
328 clearCache(dlSync);
329
330 return dlSync;
331 }
332
333 @Override
334 public DLSync updateImpl(
335 com.liferay.portlet.documentlibrary.model.DLSync dlSync, boolean merge)
336 throws SystemException {
337 dlSync = toUnwrappedModel(dlSync);
338
339 boolean isNew = dlSync.isNew();
340
341 Session session = null;
342
343 try {
344 session = openSession();
345
346 BatchSessionUtil.update(session, dlSync, merge);
347
348 dlSync.setNew(false);
349 }
350 catch (Exception e) {
351 throw processException(e);
352 }
353 finally {
354 closeSession(session);
355 }
356
357 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
358
359 if (isNew || !DLSyncModelImpl.COLUMN_BITMASK_ENABLED) {
360 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
361 }
362
363 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
364 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
365
366 clearUniqueFindersCache(dlSync);
367 cacheUniqueFindersCache(dlSync);
368
369 return dlSync;
370 }
371
372 protected DLSync toUnwrappedModel(DLSync dlSync) {
373 if (dlSync instanceof DLSyncImpl) {
374 return dlSync;
375 }
376
377 DLSyncImpl dlSyncImpl = new DLSyncImpl();
378
379 dlSyncImpl.setNew(dlSync.isNew());
380 dlSyncImpl.setPrimaryKey(dlSync.getPrimaryKey());
381
382 dlSyncImpl.setSyncId(dlSync.getSyncId());
383 dlSyncImpl.setCompanyId(dlSync.getCompanyId());
384 dlSyncImpl.setCreateDate(dlSync.getCreateDate());
385 dlSyncImpl.setModifiedDate(dlSync.getModifiedDate());
386 dlSyncImpl.setFileId(dlSync.getFileId());
387 dlSyncImpl.setFileUuid(dlSync.getFileUuid());
388 dlSyncImpl.setRepositoryId(dlSync.getRepositoryId());
389 dlSyncImpl.setParentFolderId(dlSync.getParentFolderId());
390 dlSyncImpl.setName(dlSync.getName());
391 dlSyncImpl.setDescription(dlSync.getDescription());
392 dlSyncImpl.setEvent(dlSync.getEvent());
393 dlSyncImpl.setType(dlSync.getType());
394 dlSyncImpl.setVersion(dlSync.getVersion());
395
396 return dlSyncImpl;
397 }
398
399
407 @Override
408 public DLSync findByPrimaryKey(Serializable primaryKey)
409 throws NoSuchModelException, SystemException {
410 return findByPrimaryKey(((Long)primaryKey).longValue());
411 }
412
413
421 public DLSync findByPrimaryKey(long syncId)
422 throws NoSuchSyncException, SystemException {
423 DLSync dlSync = fetchByPrimaryKey(syncId);
424
425 if (dlSync == null) {
426 if (_log.isWarnEnabled()) {
427 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + syncId);
428 }
429
430 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
431 syncId);
432 }
433
434 return dlSync;
435 }
436
437
444 @Override
445 public DLSync fetchByPrimaryKey(Serializable primaryKey)
446 throws SystemException {
447 return fetchByPrimaryKey(((Long)primaryKey).longValue());
448 }
449
450
457 public DLSync fetchByPrimaryKey(long syncId) throws SystemException {
458 DLSync dlSync = (DLSync)EntityCacheUtil.getResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
459 DLSyncImpl.class, syncId);
460
461 if (dlSync == _nullDLSync) {
462 return null;
463 }
464
465 if (dlSync == null) {
466 Session session = null;
467
468 boolean hasException = false;
469
470 try {
471 session = openSession();
472
473 dlSync = (DLSync)session.get(DLSyncImpl.class,
474 Long.valueOf(syncId));
475 }
476 catch (Exception e) {
477 hasException = true;
478
479 throw processException(e);
480 }
481 finally {
482 if (dlSync != null) {
483 cacheResult(dlSync);
484 }
485 else if (!hasException) {
486 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
487 DLSyncImpl.class, syncId, _nullDLSync);
488 }
489
490 closeSession(session);
491 }
492 }
493
494 return dlSync;
495 }
496
497
505 public DLSync findByFileId(long fileId)
506 throws NoSuchSyncException, SystemException {
507 DLSync dlSync = fetchByFileId(fileId);
508
509 if (dlSync == null) {
510 StringBundler msg = new StringBundler(4);
511
512 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
513
514 msg.append("fileId=");
515 msg.append(fileId);
516
517 msg.append(StringPool.CLOSE_CURLY_BRACE);
518
519 if (_log.isWarnEnabled()) {
520 _log.warn(msg.toString());
521 }
522
523 throw new NoSuchSyncException(msg.toString());
524 }
525
526 return dlSync;
527 }
528
529
536 public DLSync fetchByFileId(long fileId) throws SystemException {
537 return fetchByFileId(fileId, true);
538 }
539
540
548 public DLSync fetchByFileId(long fileId, boolean retrieveFromCache)
549 throws SystemException {
550 Object[] finderArgs = new Object[] { fileId };
551
552 Object result = null;
553
554 if (retrieveFromCache) {
555 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FILEID,
556 finderArgs, this);
557 }
558
559 if (result instanceof DLSync) {
560 DLSync dlSync = (DLSync)result;
561
562 if ((fileId != dlSync.getFileId())) {
563 result = null;
564 }
565 }
566
567 if (result == null) {
568 StringBundler query = new StringBundler(3);
569
570 query.append(_SQL_SELECT_DLSYNC_WHERE);
571
572 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
573
574 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
575
576 String sql = query.toString();
577
578 Session session = null;
579
580 try {
581 session = openSession();
582
583 Query q = session.createQuery(sql);
584
585 QueryPos qPos = QueryPos.getInstance(q);
586
587 qPos.add(fileId);
588
589 List<DLSync> list = q.list();
590
591 result = list;
592
593 DLSync dlSync = null;
594
595 if (list.isEmpty()) {
596 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
597 finderArgs, list);
598 }
599 else {
600 dlSync = list.get(0);
601
602 cacheResult(dlSync);
603
604 if ((dlSync.getFileId() != fileId)) {
605 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
606 finderArgs, dlSync);
607 }
608 }
609
610 return dlSync;
611 }
612 catch (Exception e) {
613 throw processException(e);
614 }
615 finally {
616 if (result == null) {
617 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
618 finderArgs);
619 }
620
621 closeSession(session);
622 }
623 }
624 else {
625 if (result instanceof List<?>) {
626 return null;
627 }
628 else {
629 return (DLSync)result;
630 }
631 }
632 }
633
634
643 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
644 long repositoryId) throws SystemException {
645 return findByC_M_R(companyId, modifiedDate, repositoryId,
646 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
647 }
648
649
664 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
665 long repositoryId, int start, int end) throws SystemException {
666 return findByC_M_R(companyId, modifiedDate, repositoryId, start, end,
667 null);
668 }
669
670
686 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
687 long repositoryId, int start, int end,
688 OrderByComparator orderByComparator) throws SystemException {
689 FinderPath finderPath = null;
690 Object[] finderArgs = null;
691
692 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R;
693 finderArgs = new Object[] {
694 companyId, modifiedDate, repositoryId,
695
696 start, end, orderByComparator
697 };
698
699 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
700 finderArgs, this);
701
702 if ((list != null) && !list.isEmpty()) {
703 for (DLSync dlSync : list) {
704 if ((companyId != dlSync.getCompanyId()) ||
705 !Validator.equals(modifiedDate, dlSync.getModifiedDate()) ||
706 (repositoryId != dlSync.getRepositoryId())) {
707 list = null;
708
709 break;
710 }
711 }
712 }
713
714 if (list == null) {
715 StringBundler query = null;
716
717 if (orderByComparator != null) {
718 query = new StringBundler(5 +
719 (orderByComparator.getOrderByFields().length * 3));
720 }
721 else {
722 query = new StringBundler(5);
723 }
724
725 query.append(_SQL_SELECT_DLSYNC_WHERE);
726
727 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
728
729 if (modifiedDate == null) {
730 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
731 }
732 else {
733 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
734 }
735
736 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
737
738 if (orderByComparator != null) {
739 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
740 orderByComparator);
741 }
742
743 else {
744 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
745 }
746
747 String sql = query.toString();
748
749 Session session = null;
750
751 try {
752 session = openSession();
753
754 Query q = session.createQuery(sql);
755
756 QueryPos qPos = QueryPos.getInstance(q);
757
758 qPos.add(companyId);
759
760 if (modifiedDate != null) {
761 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
762 }
763
764 qPos.add(repositoryId);
765
766 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start, end);
767 }
768 catch (Exception e) {
769 throw processException(e);
770 }
771 finally {
772 if (list == null) {
773 FinderCacheUtil.removeResult(finderPath, finderArgs);
774 }
775 else {
776 cacheResult(list);
777
778 FinderCacheUtil.putResult(finderPath, finderArgs, list);
779 }
780
781 closeSession(session);
782 }
783 }
784
785 return list;
786 }
787
788
799 public DLSync findByC_M_R_First(long companyId, Date modifiedDate,
800 long repositoryId, OrderByComparator orderByComparator)
801 throws NoSuchSyncException, SystemException {
802 DLSync dlSync = fetchByC_M_R_First(companyId, modifiedDate,
803 repositoryId, orderByComparator);
804
805 if (dlSync != null) {
806 return dlSync;
807 }
808
809 StringBundler msg = new StringBundler(8);
810
811 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
812
813 msg.append("companyId=");
814 msg.append(companyId);
815
816 msg.append(", modifiedDate=");
817 msg.append(modifiedDate);
818
819 msg.append(", repositoryId=");
820 msg.append(repositoryId);
821
822 msg.append(StringPool.CLOSE_CURLY_BRACE);
823
824 throw new NoSuchSyncException(msg.toString());
825 }
826
827
837 public DLSync fetchByC_M_R_First(long companyId, Date modifiedDate,
838 long repositoryId, OrderByComparator orderByComparator)
839 throws SystemException {
840 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
841 0, 1, orderByComparator);
842
843 if (!list.isEmpty()) {
844 return list.get(0);
845 }
846
847 return null;
848 }
849
850
861 public DLSync findByC_M_R_Last(long companyId, Date modifiedDate,
862 long repositoryId, OrderByComparator orderByComparator)
863 throws NoSuchSyncException, SystemException {
864 DLSync dlSync = fetchByC_M_R_Last(companyId, modifiedDate,
865 repositoryId, orderByComparator);
866
867 if (dlSync != null) {
868 return dlSync;
869 }
870
871 StringBundler msg = new StringBundler(8);
872
873 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
874
875 msg.append("companyId=");
876 msg.append(companyId);
877
878 msg.append(", modifiedDate=");
879 msg.append(modifiedDate);
880
881 msg.append(", repositoryId=");
882 msg.append(repositoryId);
883
884 msg.append(StringPool.CLOSE_CURLY_BRACE);
885
886 throw new NoSuchSyncException(msg.toString());
887 }
888
889
899 public DLSync fetchByC_M_R_Last(long companyId, Date modifiedDate,
900 long repositoryId, OrderByComparator orderByComparator)
901 throws SystemException {
902 int count = countByC_M_R(companyId, modifiedDate, repositoryId);
903
904 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
905 count - 1, count, orderByComparator);
906
907 if (!list.isEmpty()) {
908 return list.get(0);
909 }
910
911 return null;
912 }
913
914
926 public DLSync[] findByC_M_R_PrevAndNext(long syncId, long companyId,
927 Date modifiedDate, long repositoryId,
928 OrderByComparator orderByComparator)
929 throws NoSuchSyncException, SystemException {
930 DLSync dlSync = findByPrimaryKey(syncId);
931
932 Session session = null;
933
934 try {
935 session = openSession();
936
937 DLSync[] array = new DLSyncImpl[3];
938
939 array[0] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
940 modifiedDate, repositoryId, orderByComparator, true);
941
942 array[1] = dlSync;
943
944 array[2] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
945 modifiedDate, repositoryId, orderByComparator, false);
946
947 return array;
948 }
949 catch (Exception e) {
950 throw processException(e);
951 }
952 finally {
953 closeSession(session);
954 }
955 }
956
957 protected DLSync getByC_M_R_PrevAndNext(Session session, DLSync dlSync,
958 long companyId, Date modifiedDate, long repositoryId,
959 OrderByComparator orderByComparator, boolean previous) {
960 StringBundler query = null;
961
962 if (orderByComparator != null) {
963 query = new StringBundler(6 +
964 (orderByComparator.getOrderByFields().length * 6));
965 }
966 else {
967 query = new StringBundler(3);
968 }
969
970 query.append(_SQL_SELECT_DLSYNC_WHERE);
971
972 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
973
974 if (modifiedDate == null) {
975 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
976 }
977 else {
978 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
979 }
980
981 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
982
983 if (orderByComparator != null) {
984 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
985
986 if (orderByConditionFields.length > 0) {
987 query.append(WHERE_AND);
988 }
989
990 for (int i = 0; i < orderByConditionFields.length; i++) {
991 query.append(_ORDER_BY_ENTITY_ALIAS);
992 query.append(orderByConditionFields[i]);
993
994 if ((i + 1) < orderByConditionFields.length) {
995 if (orderByComparator.isAscending() ^ previous) {
996 query.append(WHERE_GREATER_THAN_HAS_NEXT);
997 }
998 else {
999 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1000 }
1001 }
1002 else {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(WHERE_GREATER_THAN);
1005 }
1006 else {
1007 query.append(WHERE_LESSER_THAN);
1008 }
1009 }
1010 }
1011
1012 query.append(ORDER_BY_CLAUSE);
1013
1014 String[] orderByFields = orderByComparator.getOrderByFields();
1015
1016 for (int i = 0; i < orderByFields.length; i++) {
1017 query.append(_ORDER_BY_ENTITY_ALIAS);
1018 query.append(orderByFields[i]);
1019
1020 if ((i + 1) < orderByFields.length) {
1021 if (orderByComparator.isAscending() ^ previous) {
1022 query.append(ORDER_BY_ASC_HAS_NEXT);
1023 }
1024 else {
1025 query.append(ORDER_BY_DESC_HAS_NEXT);
1026 }
1027 }
1028 else {
1029 if (orderByComparator.isAscending() ^ previous) {
1030 query.append(ORDER_BY_ASC);
1031 }
1032 else {
1033 query.append(ORDER_BY_DESC);
1034 }
1035 }
1036 }
1037 }
1038
1039 else {
1040 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
1041 }
1042
1043 String sql = query.toString();
1044
1045 Query q = session.createQuery(sql);
1046
1047 q.setFirstResult(0);
1048 q.setMaxResults(2);
1049
1050 QueryPos qPos = QueryPos.getInstance(q);
1051
1052 qPos.add(companyId);
1053
1054 if (modifiedDate != null) {
1055 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1056 }
1057
1058 qPos.add(repositoryId);
1059
1060 if (orderByComparator != null) {
1061 Object[] values = orderByComparator.getOrderByConditionValues(dlSync);
1062
1063 for (Object value : values) {
1064 qPos.add(value);
1065 }
1066 }
1067
1068 List<DLSync> list = q.list();
1069
1070 if (list.size() == 2) {
1071 return list.get(1);
1072 }
1073 else {
1074 return null;
1075 }
1076 }
1077
1078
1084 public List<DLSync> findAll() throws SystemException {
1085 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1086 }
1087
1088
1100 public List<DLSync> findAll(int start, int end) throws SystemException {
1101 return findAll(start, end, null);
1102 }
1103
1104
1117 public List<DLSync> findAll(int start, int end,
1118 OrderByComparator orderByComparator) throws SystemException {
1119 FinderPath finderPath = null;
1120 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1121
1122 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1123 (orderByComparator == null)) {
1124 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1125 finderArgs = FINDER_ARGS_EMPTY;
1126 }
1127 else {
1128 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1129 finderArgs = new Object[] { start, end, orderByComparator };
1130 }
1131
1132 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
1133 finderArgs, this);
1134
1135 if (list == null) {
1136 StringBundler query = null;
1137 String sql = null;
1138
1139 if (orderByComparator != null) {
1140 query = new StringBundler(2 +
1141 (orderByComparator.getOrderByFields().length * 3));
1142
1143 query.append(_SQL_SELECT_DLSYNC);
1144
1145 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1146 orderByComparator);
1147
1148 sql = query.toString();
1149 }
1150 else {
1151 sql = _SQL_SELECT_DLSYNC.concat(DLSyncModelImpl.ORDER_BY_JPQL);
1152 }
1153
1154 Session session = null;
1155
1156 try {
1157 session = openSession();
1158
1159 Query q = session.createQuery(sql);
1160
1161 if (orderByComparator == null) {
1162 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1163 end, false);
1164
1165 Collections.sort(list);
1166 }
1167 else {
1168 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1169 end);
1170 }
1171 }
1172 catch (Exception e) {
1173 throw processException(e);
1174 }
1175 finally {
1176 if (list == null) {
1177 FinderCacheUtil.removeResult(finderPath, finderArgs);
1178 }
1179 else {
1180 cacheResult(list);
1181
1182 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1183 }
1184
1185 closeSession(session);
1186 }
1187 }
1188
1189 return list;
1190 }
1191
1192
1199 public DLSync removeByFileId(long fileId)
1200 throws NoSuchSyncException, SystemException {
1201 DLSync dlSync = findByFileId(fileId);
1202
1203 return remove(dlSync);
1204 }
1205
1206
1214 public void removeByC_M_R(long companyId, Date modifiedDate,
1215 long repositoryId) throws SystemException {
1216 for (DLSync dlSync : findByC_M_R(companyId, modifiedDate, repositoryId)) {
1217 remove(dlSync);
1218 }
1219 }
1220
1221
1226 public void removeAll() throws SystemException {
1227 for (DLSync dlSync : findAll()) {
1228 remove(dlSync);
1229 }
1230 }
1231
1232
1239 public int countByFileId(long fileId) throws SystemException {
1240 Object[] finderArgs = new Object[] { fileId };
1241
1242 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FILEID,
1243 finderArgs, this);
1244
1245 if (count == null) {
1246 StringBundler query = new StringBundler(2);
1247
1248 query.append(_SQL_COUNT_DLSYNC_WHERE);
1249
1250 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
1251
1252 String sql = query.toString();
1253
1254 Session session = null;
1255
1256 try {
1257 session = openSession();
1258
1259 Query q = session.createQuery(sql);
1260
1261 QueryPos qPos = QueryPos.getInstance(q);
1262
1263 qPos.add(fileId);
1264
1265 count = (Long)q.uniqueResult();
1266 }
1267 catch (Exception e) {
1268 throw processException(e);
1269 }
1270 finally {
1271 if (count == null) {
1272 count = Long.valueOf(0);
1273 }
1274
1275 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID,
1276 finderArgs, count);
1277
1278 closeSession(session);
1279 }
1280 }
1281
1282 return count.intValue();
1283 }
1284
1285
1294 public int countByC_M_R(long companyId, Date modifiedDate, long repositoryId)
1295 throws SystemException {
1296 Object[] finderArgs = new Object[] { companyId, modifiedDate, repositoryId };
1297
1298 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R,
1299 finderArgs, this);
1300
1301 if (count == null) {
1302 StringBundler query = new StringBundler(4);
1303
1304 query.append(_SQL_COUNT_DLSYNC_WHERE);
1305
1306 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
1307
1308 if (modifiedDate == null) {
1309 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
1310 }
1311 else {
1312 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
1313 }
1314
1315 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
1316
1317 String sql = query.toString();
1318
1319 Session session = null;
1320
1321 try {
1322 session = openSession();
1323
1324 Query q = session.createQuery(sql);
1325
1326 QueryPos qPos = QueryPos.getInstance(q);
1327
1328 qPos.add(companyId);
1329
1330 if (modifiedDate != null) {
1331 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1332 }
1333
1334 qPos.add(repositoryId);
1335
1336 count = (Long)q.uniqueResult();
1337 }
1338 catch (Exception e) {
1339 throw processException(e);
1340 }
1341 finally {
1342 if (count == null) {
1343 count = Long.valueOf(0);
1344 }
1345
1346 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R,
1347 finderArgs, count);
1348
1349 closeSession(session);
1350 }
1351 }
1352
1353 return count.intValue();
1354 }
1355
1356
1362 public int countAll() throws SystemException {
1363 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1364 FINDER_ARGS_EMPTY, this);
1365
1366 if (count == null) {
1367 Session session = null;
1368
1369 try {
1370 session = openSession();
1371
1372 Query q = session.createQuery(_SQL_COUNT_DLSYNC);
1373
1374 count = (Long)q.uniqueResult();
1375 }
1376 catch (Exception e) {
1377 throw processException(e);
1378 }
1379 finally {
1380 if (count == null) {
1381 count = Long.valueOf(0);
1382 }
1383
1384 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1385 FINDER_ARGS_EMPTY, count);
1386
1387 closeSession(session);
1388 }
1389 }
1390
1391 return count.intValue();
1392 }
1393
1394
1397 public void afterPropertiesSet() {
1398 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1399 com.liferay.portal.util.PropsUtil.get(
1400 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSync")));
1401
1402 if (listenerClassNames.length > 0) {
1403 try {
1404 List<ModelListener<DLSync>> listenersList = new ArrayList<ModelListener<DLSync>>();
1405
1406 for (String listenerClassName : listenerClassNames) {
1407 Class<?> clazz = getClass();
1408
1409 listenersList.add((ModelListener<DLSync>)InstanceFactory.newInstance(
1410 clazz.getClassLoader(), listenerClassName));
1411 }
1412
1413 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1414 }
1415 catch (Exception e) {
1416 _log.error(e);
1417 }
1418 }
1419 }
1420
1421 public void destroy() {
1422 EntityCacheUtil.removeCache(DLSyncImpl.class.getName());
1423 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1424 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1425 }
1426
1427 @BeanReference(type = DLContentPersistence.class)
1428 protected DLContentPersistence dlContentPersistence;
1429 @BeanReference(type = DLFileEntryPersistence.class)
1430 protected DLFileEntryPersistence dlFileEntryPersistence;
1431 @BeanReference(type = DLFileEntryMetadataPersistence.class)
1432 protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
1433 @BeanReference(type = DLFileEntryTypePersistence.class)
1434 protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
1435 @BeanReference(type = DLFileRankPersistence.class)
1436 protected DLFileRankPersistence dlFileRankPersistence;
1437 @BeanReference(type = DLFileShortcutPersistence.class)
1438 protected DLFileShortcutPersistence dlFileShortcutPersistence;
1439 @BeanReference(type = DLFileVersionPersistence.class)
1440 protected DLFileVersionPersistence dlFileVersionPersistence;
1441 @BeanReference(type = DLFolderPersistence.class)
1442 protected DLFolderPersistence dlFolderPersistence;
1443 @BeanReference(type = DLSyncPersistence.class)
1444 protected DLSyncPersistence dlSyncPersistence;
1445 @BeanReference(type = RepositoryPersistence.class)
1446 protected RepositoryPersistence repositoryPersistence;
1447 @BeanReference(type = ResourcePersistence.class)
1448 protected ResourcePersistence resourcePersistence;
1449 @BeanReference(type = UserPersistence.class)
1450 protected UserPersistence userPersistence;
1451 private static final String _SQL_SELECT_DLSYNC = "SELECT dlSync FROM DLSync dlSync";
1452 private static final String _SQL_SELECT_DLSYNC_WHERE = "SELECT dlSync FROM DLSync dlSync WHERE ";
1453 private static final String _SQL_COUNT_DLSYNC = "SELECT COUNT(dlSync) FROM DLSync dlSync";
1454 private static final String _SQL_COUNT_DLSYNC_WHERE = "SELECT COUNT(dlSync) FROM DLSync dlSync WHERE ";
1455 private static final String _FINDER_COLUMN_FILEID_FILEID_2 = "dlSync.fileId = ?";
1456 private static final String _FINDER_COLUMN_C_M_R_COMPANYID_2 = "dlSync.companyId = ? AND ";
1457 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_1 = "dlSync.modifiedDate >= NULL AND ";
1458 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_2 = "dlSync.modifiedDate >= ? AND ";
1459 private static final String _FINDER_COLUMN_C_M_R_REPOSITORYID_2 = "dlSync.repositoryId = ?";
1460 private static final String _ORDER_BY_ENTITY_ALIAS = "dlSync.";
1461 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSync exists with the primary key ";
1462 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSync exists with the key {";
1463 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1464 private static Log _log = LogFactoryUtil.getLog(DLSyncPersistenceImpl.class);
1465 private static DLSync _nullDLSync = new DLSyncImpl() {
1466 @Override
1467 public Object clone() {
1468 return this;
1469 }
1470
1471 @Override
1472 public CacheModel<DLSync> toCacheModel() {
1473 return _nullDLSyncCacheModel;
1474 }
1475 };
1476
1477 private static CacheModel<DLSync> _nullDLSyncCacheModel = new CacheModel<DLSync>() {
1478 public DLSync toEntityModel() {
1479 return _nullDLSync;
1480 }
1481 };
1482 }