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 clearUniqueFindersCache(DLSync dlSync) {
201 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
202 new Object[] { Long.valueOf(dlSync.getFileId()) });
203 }
204
205
211 public DLSync create(long syncId) {
212 DLSync dlSync = new DLSyncImpl();
213
214 dlSync.setNew(true);
215 dlSync.setPrimaryKey(syncId);
216
217 return dlSync;
218 }
219
220
228 public DLSync remove(long syncId)
229 throws NoSuchSyncException, SystemException {
230 return remove(Long.valueOf(syncId));
231 }
232
233
241 @Override
242 public DLSync remove(Serializable primaryKey)
243 throws NoSuchSyncException, SystemException {
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 DLSync dlSync = (DLSync)session.get(DLSyncImpl.class, primaryKey);
250
251 if (dlSync == null) {
252 if (_log.isWarnEnabled()) {
253 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
254 }
255
256 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
257 primaryKey);
258 }
259
260 return remove(dlSync);
261 }
262 catch (NoSuchSyncException nsee) {
263 throw nsee;
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 @Override
274 protected DLSync removeImpl(DLSync dlSync) throws SystemException {
275 dlSync = toUnwrappedModel(dlSync);
276
277 Session session = null;
278
279 try {
280 session = openSession();
281
282 BatchSessionUtil.delete(session, dlSync);
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 closeSession(session);
289 }
290
291 clearCache(dlSync);
292
293 return dlSync;
294 }
295
296 @Override
297 public DLSync updateImpl(
298 com.liferay.portlet.documentlibrary.model.DLSync dlSync, boolean merge)
299 throws SystemException {
300 dlSync = toUnwrappedModel(dlSync);
301
302 boolean isNew = dlSync.isNew();
303
304 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
305
306 Session session = null;
307
308 try {
309 session = openSession();
310
311 BatchSessionUtil.update(session, dlSync, merge);
312
313 dlSync.setNew(false);
314 }
315 catch (Exception e) {
316 throw processException(e);
317 }
318 finally {
319 closeSession(session);
320 }
321
322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
323
324 if (isNew || !DLSyncModelImpl.COLUMN_BITMASK_ENABLED) {
325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
326 }
327
328 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
329 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
330
331 if (isNew) {
332 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
333 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
334 }
335 else {
336 if ((dlSyncModelImpl.getColumnBitmask() &
337 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
338 Object[] args = new Object[] {
339 Long.valueOf(dlSyncModelImpl.getOriginalFileId())
340 };
341
342 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
343
344 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
345
346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
347 new Object[] { Long.valueOf(dlSync.getFileId()) }, dlSync);
348 }
349 }
350
351 return dlSync;
352 }
353
354 protected DLSync toUnwrappedModel(DLSync dlSync) {
355 if (dlSync instanceof DLSyncImpl) {
356 return dlSync;
357 }
358
359 DLSyncImpl dlSyncImpl = new DLSyncImpl();
360
361 dlSyncImpl.setNew(dlSync.isNew());
362 dlSyncImpl.setPrimaryKey(dlSync.getPrimaryKey());
363
364 dlSyncImpl.setSyncId(dlSync.getSyncId());
365 dlSyncImpl.setCompanyId(dlSync.getCompanyId());
366 dlSyncImpl.setCreateDate(dlSync.getCreateDate());
367 dlSyncImpl.setModifiedDate(dlSync.getModifiedDate());
368 dlSyncImpl.setFileId(dlSync.getFileId());
369 dlSyncImpl.setFileUuid(dlSync.getFileUuid());
370 dlSyncImpl.setRepositoryId(dlSync.getRepositoryId());
371 dlSyncImpl.setParentFolderId(dlSync.getParentFolderId());
372 dlSyncImpl.setName(dlSync.getName());
373 dlSyncImpl.setDescription(dlSync.getDescription());
374 dlSyncImpl.setEvent(dlSync.getEvent());
375 dlSyncImpl.setType(dlSync.getType());
376 dlSyncImpl.setVersion(dlSync.getVersion());
377
378 return dlSyncImpl;
379 }
380
381
389 @Override
390 public DLSync findByPrimaryKey(Serializable primaryKey)
391 throws NoSuchModelException, SystemException {
392 return findByPrimaryKey(((Long)primaryKey).longValue());
393 }
394
395
403 public DLSync findByPrimaryKey(long syncId)
404 throws NoSuchSyncException, SystemException {
405 DLSync dlSync = fetchByPrimaryKey(syncId);
406
407 if (dlSync == null) {
408 if (_log.isWarnEnabled()) {
409 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + syncId);
410 }
411
412 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
413 syncId);
414 }
415
416 return dlSync;
417 }
418
419
426 @Override
427 public DLSync fetchByPrimaryKey(Serializable primaryKey)
428 throws SystemException {
429 return fetchByPrimaryKey(((Long)primaryKey).longValue());
430 }
431
432
439 public DLSync fetchByPrimaryKey(long syncId) throws SystemException {
440 DLSync dlSync = (DLSync)EntityCacheUtil.getResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
441 DLSyncImpl.class, syncId);
442
443 if (dlSync == _nullDLSync) {
444 return null;
445 }
446
447 if (dlSync == null) {
448 Session session = null;
449
450 boolean hasException = false;
451
452 try {
453 session = openSession();
454
455 dlSync = (DLSync)session.get(DLSyncImpl.class,
456 Long.valueOf(syncId));
457 }
458 catch (Exception e) {
459 hasException = true;
460
461 throw processException(e);
462 }
463 finally {
464 if (dlSync != null) {
465 cacheResult(dlSync);
466 }
467 else if (!hasException) {
468 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
469 DLSyncImpl.class, syncId, _nullDLSync);
470 }
471
472 closeSession(session);
473 }
474 }
475
476 return dlSync;
477 }
478
479
487 public DLSync findByFileId(long fileId)
488 throws NoSuchSyncException, SystemException {
489 DLSync dlSync = fetchByFileId(fileId);
490
491 if (dlSync == null) {
492 StringBundler msg = new StringBundler(4);
493
494 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
495
496 msg.append("fileId=");
497 msg.append(fileId);
498
499 msg.append(StringPool.CLOSE_CURLY_BRACE);
500
501 if (_log.isWarnEnabled()) {
502 _log.warn(msg.toString());
503 }
504
505 throw new NoSuchSyncException(msg.toString());
506 }
507
508 return dlSync;
509 }
510
511
518 public DLSync fetchByFileId(long fileId) throws SystemException {
519 return fetchByFileId(fileId, true);
520 }
521
522
530 public DLSync fetchByFileId(long fileId, boolean retrieveFromCache)
531 throws SystemException {
532 Object[] finderArgs = new Object[] { fileId };
533
534 Object result = null;
535
536 if (retrieveFromCache) {
537 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FILEID,
538 finderArgs, this);
539 }
540
541 if (result instanceof DLSync) {
542 DLSync dlSync = (DLSync)result;
543
544 if ((fileId != dlSync.getFileId())) {
545 result = null;
546 }
547 }
548
549 if (result == null) {
550 StringBundler query = new StringBundler(3);
551
552 query.append(_SQL_SELECT_DLSYNC_WHERE);
553
554 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
555
556 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
557
558 String sql = query.toString();
559
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 Query q = session.createQuery(sql);
566
567 QueryPos qPos = QueryPos.getInstance(q);
568
569 qPos.add(fileId);
570
571 List<DLSync> list = q.list();
572
573 result = list;
574
575 DLSync dlSync = null;
576
577 if (list.isEmpty()) {
578 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
579 finderArgs, list);
580 }
581 else {
582 dlSync = list.get(0);
583
584 cacheResult(dlSync);
585
586 if ((dlSync.getFileId() != fileId)) {
587 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
588 finderArgs, dlSync);
589 }
590 }
591
592 return dlSync;
593 }
594 catch (Exception e) {
595 throw processException(e);
596 }
597 finally {
598 if (result == null) {
599 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
600 finderArgs);
601 }
602
603 closeSession(session);
604 }
605 }
606 else {
607 if (result instanceof List<?>) {
608 return null;
609 }
610 else {
611 return (DLSync)result;
612 }
613 }
614 }
615
616
625 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
626 long repositoryId) throws SystemException {
627 return findByC_M_R(companyId, modifiedDate, repositoryId,
628 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
629 }
630
631
646 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
647 long repositoryId, int start, int end) throws SystemException {
648 return findByC_M_R(companyId, modifiedDate, repositoryId, start, end,
649 null);
650 }
651
652
668 public List<DLSync> findByC_M_R(long companyId, Date modifiedDate,
669 long repositoryId, int start, int end,
670 OrderByComparator orderByComparator) throws SystemException {
671 FinderPath finderPath = null;
672 Object[] finderArgs = null;
673
674 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R;
675 finderArgs = new Object[] {
676 companyId, modifiedDate, repositoryId,
677
678 start, end, orderByComparator
679 };
680
681 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
682 finderArgs, this);
683
684 if ((list != null) && !list.isEmpty()) {
685 for (DLSync dlSync : list) {
686 if ((companyId != dlSync.getCompanyId()) ||
687 !Validator.equals(modifiedDate, dlSync.getModifiedDate()) ||
688 (repositoryId != dlSync.getRepositoryId())) {
689 list = null;
690
691 break;
692 }
693 }
694 }
695
696 if (list == null) {
697 StringBundler query = null;
698
699 if (orderByComparator != null) {
700 query = new StringBundler(5 +
701 (orderByComparator.getOrderByFields().length * 3));
702 }
703 else {
704 query = new StringBundler(5);
705 }
706
707 query.append(_SQL_SELECT_DLSYNC_WHERE);
708
709 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
710
711 if (modifiedDate == null) {
712 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
713 }
714 else {
715 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
716 }
717
718 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
719
720 if (orderByComparator != null) {
721 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
722 orderByComparator);
723 }
724
725 else {
726 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
727 }
728
729 String sql = query.toString();
730
731 Session session = null;
732
733 try {
734 session = openSession();
735
736 Query q = session.createQuery(sql);
737
738 QueryPos qPos = QueryPos.getInstance(q);
739
740 qPos.add(companyId);
741
742 if (modifiedDate != null) {
743 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
744 }
745
746 qPos.add(repositoryId);
747
748 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start, end);
749 }
750 catch (Exception e) {
751 throw processException(e);
752 }
753 finally {
754 if (list == null) {
755 FinderCacheUtil.removeResult(finderPath, finderArgs);
756 }
757 else {
758 cacheResult(list);
759
760 FinderCacheUtil.putResult(finderPath, finderArgs, list);
761 }
762
763 closeSession(session);
764 }
765 }
766
767 return list;
768 }
769
770
781 public DLSync findByC_M_R_First(long companyId, Date modifiedDate,
782 long repositoryId, OrderByComparator orderByComparator)
783 throws NoSuchSyncException, SystemException {
784 DLSync dlSync = fetchByC_M_R_First(companyId, modifiedDate,
785 repositoryId, orderByComparator);
786
787 if (dlSync != null) {
788 return dlSync;
789 }
790
791 StringBundler msg = new StringBundler(8);
792
793 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
794
795 msg.append("companyId=");
796 msg.append(companyId);
797
798 msg.append(", modifiedDate=");
799 msg.append(modifiedDate);
800
801 msg.append(", repositoryId=");
802 msg.append(repositoryId);
803
804 msg.append(StringPool.CLOSE_CURLY_BRACE);
805
806 throw new NoSuchSyncException(msg.toString());
807 }
808
809
819 public DLSync fetchByC_M_R_First(long companyId, Date modifiedDate,
820 long repositoryId, OrderByComparator orderByComparator)
821 throws SystemException {
822 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
823 0, 1, orderByComparator);
824
825 if (!list.isEmpty()) {
826 return list.get(0);
827 }
828
829 return null;
830 }
831
832
843 public DLSync findByC_M_R_Last(long companyId, Date modifiedDate,
844 long repositoryId, OrderByComparator orderByComparator)
845 throws NoSuchSyncException, SystemException {
846 DLSync dlSync = fetchByC_M_R_Last(companyId, modifiedDate,
847 repositoryId, orderByComparator);
848
849 if (dlSync != null) {
850 return dlSync;
851 }
852
853 StringBundler msg = new StringBundler(8);
854
855 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
856
857 msg.append("companyId=");
858 msg.append(companyId);
859
860 msg.append(", modifiedDate=");
861 msg.append(modifiedDate);
862
863 msg.append(", repositoryId=");
864 msg.append(repositoryId);
865
866 msg.append(StringPool.CLOSE_CURLY_BRACE);
867
868 throw new NoSuchSyncException(msg.toString());
869 }
870
871
881 public DLSync fetchByC_M_R_Last(long companyId, Date modifiedDate,
882 long repositoryId, OrderByComparator orderByComparator)
883 throws SystemException {
884 int count = countByC_M_R(companyId, modifiedDate, repositoryId);
885
886 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
887 count - 1, count, orderByComparator);
888
889 if (!list.isEmpty()) {
890 return list.get(0);
891 }
892
893 return null;
894 }
895
896
908 public DLSync[] findByC_M_R_PrevAndNext(long syncId, long companyId,
909 Date modifiedDate, long repositoryId,
910 OrderByComparator orderByComparator)
911 throws NoSuchSyncException, SystemException {
912 DLSync dlSync = findByPrimaryKey(syncId);
913
914 Session session = null;
915
916 try {
917 session = openSession();
918
919 DLSync[] array = new DLSyncImpl[3];
920
921 array[0] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
922 modifiedDate, repositoryId, orderByComparator, true);
923
924 array[1] = dlSync;
925
926 array[2] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
927 modifiedDate, repositoryId, orderByComparator, false);
928
929 return array;
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 closeSession(session);
936 }
937 }
938
939 protected DLSync getByC_M_R_PrevAndNext(Session session, DLSync dlSync,
940 long companyId, Date modifiedDate, long repositoryId,
941 OrderByComparator orderByComparator, boolean previous) {
942 StringBundler query = null;
943
944 if (orderByComparator != null) {
945 query = new StringBundler(6 +
946 (orderByComparator.getOrderByFields().length * 6));
947 }
948 else {
949 query = new StringBundler(3);
950 }
951
952 query.append(_SQL_SELECT_DLSYNC_WHERE);
953
954 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
955
956 if (modifiedDate == null) {
957 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
958 }
959 else {
960 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
961 }
962
963 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
964
965 if (orderByComparator != null) {
966 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
967
968 if (orderByConditionFields.length > 0) {
969 query.append(WHERE_AND);
970 }
971
972 for (int i = 0; i < orderByConditionFields.length; i++) {
973 query.append(_ORDER_BY_ENTITY_ALIAS);
974 query.append(orderByConditionFields[i]);
975
976 if ((i + 1) < orderByConditionFields.length) {
977 if (orderByComparator.isAscending() ^ previous) {
978 query.append(WHERE_GREATER_THAN_HAS_NEXT);
979 }
980 else {
981 query.append(WHERE_LESSER_THAN_HAS_NEXT);
982 }
983 }
984 else {
985 if (orderByComparator.isAscending() ^ previous) {
986 query.append(WHERE_GREATER_THAN);
987 }
988 else {
989 query.append(WHERE_LESSER_THAN);
990 }
991 }
992 }
993
994 query.append(ORDER_BY_CLAUSE);
995
996 String[] orderByFields = orderByComparator.getOrderByFields();
997
998 for (int i = 0; i < orderByFields.length; i++) {
999 query.append(_ORDER_BY_ENTITY_ALIAS);
1000 query.append(orderByFields[i]);
1001
1002 if ((i + 1) < orderByFields.length) {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(ORDER_BY_ASC_HAS_NEXT);
1005 }
1006 else {
1007 query.append(ORDER_BY_DESC_HAS_NEXT);
1008 }
1009 }
1010 else {
1011 if (orderByComparator.isAscending() ^ previous) {
1012 query.append(ORDER_BY_ASC);
1013 }
1014 else {
1015 query.append(ORDER_BY_DESC);
1016 }
1017 }
1018 }
1019 }
1020
1021 else {
1022 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
1023 }
1024
1025 String sql = query.toString();
1026
1027 Query q = session.createQuery(sql);
1028
1029 q.setFirstResult(0);
1030 q.setMaxResults(2);
1031
1032 QueryPos qPos = QueryPos.getInstance(q);
1033
1034 qPos.add(companyId);
1035
1036 if (modifiedDate != null) {
1037 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1038 }
1039
1040 qPos.add(repositoryId);
1041
1042 if (orderByComparator != null) {
1043 Object[] values = orderByComparator.getOrderByConditionValues(dlSync);
1044
1045 for (Object value : values) {
1046 qPos.add(value);
1047 }
1048 }
1049
1050 List<DLSync> list = q.list();
1051
1052 if (list.size() == 2) {
1053 return list.get(1);
1054 }
1055 else {
1056 return null;
1057 }
1058 }
1059
1060
1066 public List<DLSync> findAll() throws SystemException {
1067 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1068 }
1069
1070
1082 public List<DLSync> findAll(int start, int end) throws SystemException {
1083 return findAll(start, end, null);
1084 }
1085
1086
1099 public List<DLSync> findAll(int start, int end,
1100 OrderByComparator orderByComparator) throws SystemException {
1101 FinderPath finderPath = null;
1102 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1103
1104 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1105 (orderByComparator == null)) {
1106 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1107 finderArgs = FINDER_ARGS_EMPTY;
1108 }
1109 else {
1110 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1111 finderArgs = new Object[] { start, end, orderByComparator };
1112 }
1113
1114 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
1115 finderArgs, this);
1116
1117 if (list == null) {
1118 StringBundler query = null;
1119 String sql = null;
1120
1121 if (orderByComparator != null) {
1122 query = new StringBundler(2 +
1123 (orderByComparator.getOrderByFields().length * 3));
1124
1125 query.append(_SQL_SELECT_DLSYNC);
1126
1127 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1128 orderByComparator);
1129
1130 sql = query.toString();
1131 }
1132 else {
1133 sql = _SQL_SELECT_DLSYNC.concat(DLSyncModelImpl.ORDER_BY_JPQL);
1134 }
1135
1136 Session session = null;
1137
1138 try {
1139 session = openSession();
1140
1141 Query q = session.createQuery(sql);
1142
1143 if (orderByComparator == null) {
1144 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1145 end, false);
1146
1147 Collections.sort(list);
1148 }
1149 else {
1150 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1151 end);
1152 }
1153 }
1154 catch (Exception e) {
1155 throw processException(e);
1156 }
1157 finally {
1158 if (list == null) {
1159 FinderCacheUtil.removeResult(finderPath, finderArgs);
1160 }
1161 else {
1162 cacheResult(list);
1163
1164 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1165 }
1166
1167 closeSession(session);
1168 }
1169 }
1170
1171 return list;
1172 }
1173
1174
1181 public DLSync removeByFileId(long fileId)
1182 throws NoSuchSyncException, SystemException {
1183 DLSync dlSync = findByFileId(fileId);
1184
1185 return remove(dlSync);
1186 }
1187
1188
1196 public void removeByC_M_R(long companyId, Date modifiedDate,
1197 long repositoryId) throws SystemException {
1198 for (DLSync dlSync : findByC_M_R(companyId, modifiedDate, repositoryId)) {
1199 remove(dlSync);
1200 }
1201 }
1202
1203
1208 public void removeAll() throws SystemException {
1209 for (DLSync dlSync : findAll()) {
1210 remove(dlSync);
1211 }
1212 }
1213
1214
1221 public int countByFileId(long fileId) throws SystemException {
1222 Object[] finderArgs = new Object[] { fileId };
1223
1224 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FILEID,
1225 finderArgs, this);
1226
1227 if (count == null) {
1228 StringBundler query = new StringBundler(2);
1229
1230 query.append(_SQL_COUNT_DLSYNC_WHERE);
1231
1232 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
1233
1234 String sql = query.toString();
1235
1236 Session session = null;
1237
1238 try {
1239 session = openSession();
1240
1241 Query q = session.createQuery(sql);
1242
1243 QueryPos qPos = QueryPos.getInstance(q);
1244
1245 qPos.add(fileId);
1246
1247 count = (Long)q.uniqueResult();
1248 }
1249 catch (Exception e) {
1250 throw processException(e);
1251 }
1252 finally {
1253 if (count == null) {
1254 count = Long.valueOf(0);
1255 }
1256
1257 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID,
1258 finderArgs, count);
1259
1260 closeSession(session);
1261 }
1262 }
1263
1264 return count.intValue();
1265 }
1266
1267
1276 public int countByC_M_R(long companyId, Date modifiedDate, long repositoryId)
1277 throws SystemException {
1278 Object[] finderArgs = new Object[] { companyId, modifiedDate, repositoryId };
1279
1280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R,
1281 finderArgs, this);
1282
1283 if (count == null) {
1284 StringBundler query = new StringBundler(4);
1285
1286 query.append(_SQL_COUNT_DLSYNC_WHERE);
1287
1288 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
1289
1290 if (modifiedDate == null) {
1291 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_1);
1292 }
1293 else {
1294 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
1295 }
1296
1297 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
1298
1299 String sql = query.toString();
1300
1301 Session session = null;
1302
1303 try {
1304 session = openSession();
1305
1306 Query q = session.createQuery(sql);
1307
1308 QueryPos qPos = QueryPos.getInstance(q);
1309
1310 qPos.add(companyId);
1311
1312 if (modifiedDate != null) {
1313 qPos.add(CalendarUtil.getTimestamp(modifiedDate));
1314 }
1315
1316 qPos.add(repositoryId);
1317
1318 count = (Long)q.uniqueResult();
1319 }
1320 catch (Exception e) {
1321 throw processException(e);
1322 }
1323 finally {
1324 if (count == null) {
1325 count = Long.valueOf(0);
1326 }
1327
1328 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R,
1329 finderArgs, count);
1330
1331 closeSession(session);
1332 }
1333 }
1334
1335 return count.intValue();
1336 }
1337
1338
1344 public int countAll() throws SystemException {
1345 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1346 FINDER_ARGS_EMPTY, this);
1347
1348 if (count == null) {
1349 Session session = null;
1350
1351 try {
1352 session = openSession();
1353
1354 Query q = session.createQuery(_SQL_COUNT_DLSYNC);
1355
1356 count = (Long)q.uniqueResult();
1357 }
1358 catch (Exception e) {
1359 throw processException(e);
1360 }
1361 finally {
1362 if (count == null) {
1363 count = Long.valueOf(0);
1364 }
1365
1366 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1367 FINDER_ARGS_EMPTY, count);
1368
1369 closeSession(session);
1370 }
1371 }
1372
1373 return count.intValue();
1374 }
1375
1376
1379 public void afterPropertiesSet() {
1380 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1381 com.liferay.portal.util.PropsUtil.get(
1382 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSync")));
1383
1384 if (listenerClassNames.length > 0) {
1385 try {
1386 List<ModelListener<DLSync>> listenersList = new ArrayList<ModelListener<DLSync>>();
1387
1388 for (String listenerClassName : listenerClassNames) {
1389 listenersList.add((ModelListener<DLSync>)InstanceFactory.newInstance(
1390 listenerClassName));
1391 }
1392
1393 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1394 }
1395 catch (Exception e) {
1396 _log.error(e);
1397 }
1398 }
1399 }
1400
1401 public void destroy() {
1402 EntityCacheUtil.removeCache(DLSyncImpl.class.getName());
1403 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1404 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1405 }
1406
1407 @BeanReference(type = DLContentPersistence.class)
1408 protected DLContentPersistence dlContentPersistence;
1409 @BeanReference(type = DLFileEntryPersistence.class)
1410 protected DLFileEntryPersistence dlFileEntryPersistence;
1411 @BeanReference(type = DLFileEntryMetadataPersistence.class)
1412 protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
1413 @BeanReference(type = DLFileEntryTypePersistence.class)
1414 protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
1415 @BeanReference(type = DLFileRankPersistence.class)
1416 protected DLFileRankPersistence dlFileRankPersistence;
1417 @BeanReference(type = DLFileShortcutPersistence.class)
1418 protected DLFileShortcutPersistence dlFileShortcutPersistence;
1419 @BeanReference(type = DLFileVersionPersistence.class)
1420 protected DLFileVersionPersistence dlFileVersionPersistence;
1421 @BeanReference(type = DLFolderPersistence.class)
1422 protected DLFolderPersistence dlFolderPersistence;
1423 @BeanReference(type = DLSyncPersistence.class)
1424 protected DLSyncPersistence dlSyncPersistence;
1425 @BeanReference(type = RepositoryPersistence.class)
1426 protected RepositoryPersistence repositoryPersistence;
1427 @BeanReference(type = ResourcePersistence.class)
1428 protected ResourcePersistence resourcePersistence;
1429 @BeanReference(type = UserPersistence.class)
1430 protected UserPersistence userPersistence;
1431 private static final String _SQL_SELECT_DLSYNC = "SELECT dlSync FROM DLSync dlSync";
1432 private static final String _SQL_SELECT_DLSYNC_WHERE = "SELECT dlSync FROM DLSync dlSync WHERE ";
1433 private static final String _SQL_COUNT_DLSYNC = "SELECT COUNT(dlSync) FROM DLSync dlSync";
1434 private static final String _SQL_COUNT_DLSYNC_WHERE = "SELECT COUNT(dlSync) FROM DLSync dlSync WHERE ";
1435 private static final String _FINDER_COLUMN_FILEID_FILEID_2 = "dlSync.fileId = ?";
1436 private static final String _FINDER_COLUMN_C_M_R_COMPANYID_2 = "dlSync.companyId = ? AND ";
1437 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_1 = "dlSync.modifiedDate >= NULL AND ";
1438 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_2 = "dlSync.modifiedDate >= ? AND ";
1439 private static final String _FINDER_COLUMN_C_M_R_REPOSITORYID_2 = "dlSync.repositoryId = ?";
1440 private static final String _ORDER_BY_ENTITY_ALIAS = "dlSync.";
1441 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSync exists with the primary key ";
1442 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSync exists with the key {";
1443 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1444 private static Log _log = LogFactoryUtil.getLog(DLSyncPersistenceImpl.class);
1445 private static DLSync _nullDLSync = new DLSyncImpl() {
1446 @Override
1447 public Object clone() {
1448 return this;
1449 }
1450
1451 @Override
1452 public CacheModel<DLSync> toCacheModel() {
1453 return _nullDLSyncCacheModel;
1454 }
1455 };
1456
1457 private static CacheModel<DLSync> _nullDLSyncCacheModel = new CacheModel<DLSync>() {
1458 public DLSync toEntityModel() {
1459 return _nullDLSync;
1460 }
1461 };
1462 }