001
014
015 package com.liferay.portlet.documentlibrary.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.documentlibrary.NoSuchSyncException;
040 import com.liferay.portlet.documentlibrary.model.DLSync;
041 import com.liferay.portlet.documentlibrary.model.impl.DLSyncImpl;
042 import com.liferay.portlet.documentlibrary.model.impl.DLSyncModelImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class DLSyncPersistenceImpl extends BasePersistenceImpl<DLSync>
063 implements DLSyncPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = DLSyncImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
075 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
078 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
081 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_FETCH_BY_FILEID = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
084 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
085 FINDER_CLASS_NAME_ENTITY, "fetchByFileId",
086 new String[] { Long.class.getName() },
087 DLSyncModelImpl.FILEID_COLUMN_BITMASK);
088 public static final FinderPath FINDER_PATH_COUNT_BY_FILEID = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
089 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileId",
091 new String[] { Long.class.getName() });
092
093
101 public DLSync findByFileId(long fileId)
102 throws NoSuchSyncException, SystemException {
103 DLSync dlSync = fetchByFileId(fileId);
104
105 if (dlSync == null) {
106 StringBundler msg = new StringBundler(4);
107
108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
109
110 msg.append("fileId=");
111 msg.append(fileId);
112
113 msg.append(StringPool.CLOSE_CURLY_BRACE);
114
115 if (_log.isWarnEnabled()) {
116 _log.warn(msg.toString());
117 }
118
119 throw new NoSuchSyncException(msg.toString());
120 }
121
122 return dlSync;
123 }
124
125
132 public DLSync fetchByFileId(long fileId) throws SystemException {
133 return fetchByFileId(fileId, true);
134 }
135
136
144 public DLSync fetchByFileId(long fileId, boolean retrieveFromCache)
145 throws SystemException {
146 Object[] finderArgs = new Object[] { fileId };
147
148 Object result = null;
149
150 if (retrieveFromCache) {
151 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FILEID,
152 finderArgs, this);
153 }
154
155 if (result instanceof DLSync) {
156 DLSync dlSync = (DLSync)result;
157
158 if ((fileId != dlSync.getFileId())) {
159 result = null;
160 }
161 }
162
163 if (result == null) {
164 StringBundler query = new StringBundler(3);
165
166 query.append(_SQL_SELECT_DLSYNC_WHERE);
167
168 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
169
170 String sql = query.toString();
171
172 Session session = null;
173
174 try {
175 session = openSession();
176
177 Query q = session.createQuery(sql);
178
179 QueryPos qPos = QueryPos.getInstance(q);
180
181 qPos.add(fileId);
182
183 List<DLSync> list = q.list();
184
185 if (list.isEmpty()) {
186 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
187 finderArgs, list);
188 }
189 else {
190 DLSync dlSync = list.get(0);
191
192 result = dlSync;
193
194 cacheResult(dlSync);
195
196 if ((dlSync.getFileId() != fileId)) {
197 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
198 finderArgs, dlSync);
199 }
200 }
201 }
202 catch (Exception e) {
203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID,
204 finderArgs);
205
206 throw processException(e);
207 }
208 finally {
209 closeSession(session);
210 }
211 }
212
213 if (result instanceof List<?>) {
214 return null;
215 }
216 else {
217 return (DLSync)result;
218 }
219 }
220
221
228 public DLSync removeByFileId(long fileId)
229 throws NoSuchSyncException, SystemException {
230 DLSync dlSync = findByFileId(fileId);
231
232 return remove(dlSync);
233 }
234
235
242 public int countByFileId(long fileId) throws SystemException {
243 FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEID;
244
245 Object[] finderArgs = new Object[] { fileId };
246
247 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
248 this);
249
250 if (count == null) {
251 StringBundler query = new StringBundler(2);
252
253 query.append(_SQL_COUNT_DLSYNC_WHERE);
254
255 query.append(_FINDER_COLUMN_FILEID_FILEID_2);
256
257 String sql = query.toString();
258
259 Session session = null;
260
261 try {
262 session = openSession();
263
264 Query q = session.createQuery(sql);
265
266 QueryPos qPos = QueryPos.getInstance(q);
267
268 qPos.add(fileId);
269
270 count = (Long)q.uniqueResult();
271
272 FinderCacheUtil.putResult(finderPath, finderArgs, count);
273 }
274 catch (Exception e) {
275 FinderCacheUtil.removeResult(finderPath, finderArgs);
276
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282 }
283
284 return count.intValue();
285 }
286
287 private static final String _FINDER_COLUMN_FILEID_FILEID_2 = "dlSync.fileId = ?";
288 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
289 DLSyncModelImpl.FINDER_CACHE_ENABLED, DLSyncImpl.class,
290 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_M_R",
291 new String[] {
292 Long.class.getName(), Long.class.getName(), Long.class.getName(),
293
294 Integer.class.getName(), Integer.class.getName(),
295 OrderByComparator.class.getName()
296 });
297 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R = new FinderPath(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
298 DLSyncModelImpl.FINDER_CACHE_ENABLED, Long.class,
299 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_M_R",
300 new String[] {
301 Long.class.getName(), Long.class.getName(), Long.class.getName()
302 });
303
304
313 public List<DLSync> findByC_M_R(long companyId, long modifiedDate,
314 long repositoryId) throws SystemException {
315 return findByC_M_R(companyId, modifiedDate, repositoryId,
316 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
317 }
318
319
334 public List<DLSync> findByC_M_R(long companyId, long modifiedDate,
335 long repositoryId, int start, int end) throws SystemException {
336 return findByC_M_R(companyId, modifiedDate, repositoryId, start, end,
337 null);
338 }
339
340
356 public List<DLSync> findByC_M_R(long companyId, long modifiedDate,
357 long repositoryId, int start, int end,
358 OrderByComparator orderByComparator) throws SystemException {
359 boolean pagination = true;
360 FinderPath finderPath = null;
361 Object[] finderArgs = null;
362
363 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_M_R;
364 finderArgs = new Object[] {
365 companyId, modifiedDate, repositoryId,
366
367 start, end, orderByComparator
368 };
369
370 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
371 finderArgs, this);
372
373 if ((list != null) && !list.isEmpty()) {
374 for (DLSync dlSync : list) {
375 if ((companyId != dlSync.getCompanyId()) ||
376 (modifiedDate != dlSync.getModifiedDate()) ||
377 (repositoryId != dlSync.getRepositoryId())) {
378 list = null;
379
380 break;
381 }
382 }
383 }
384
385 if (list == null) {
386 StringBundler query = null;
387
388 if (orderByComparator != null) {
389 query = new StringBundler(5 +
390 (orderByComparator.getOrderByFields().length * 3));
391 }
392 else {
393 query = new StringBundler(5);
394 }
395
396 query.append(_SQL_SELECT_DLSYNC_WHERE);
397
398 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
399
400 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
401
402 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
403
404 if (orderByComparator != null) {
405 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
406 orderByComparator);
407 }
408 else
409 if (pagination) {
410 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
411 }
412
413 String sql = query.toString();
414
415 Session session = null;
416
417 try {
418 session = openSession();
419
420 Query q = session.createQuery(sql);
421
422 QueryPos qPos = QueryPos.getInstance(q);
423
424 qPos.add(companyId);
425
426 qPos.add(modifiedDate);
427
428 qPos.add(repositoryId);
429
430 if (!pagination) {
431 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
432 end, false);
433
434 Collections.sort(list);
435
436 list = new UnmodifiableList<DLSync>(list);
437 }
438 else {
439 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
440 end);
441 }
442
443 cacheResult(list);
444
445 FinderCacheUtil.putResult(finderPath, finderArgs, list);
446 }
447 catch (Exception e) {
448 FinderCacheUtil.removeResult(finderPath, finderArgs);
449
450 throw processException(e);
451 }
452 finally {
453 closeSession(session);
454 }
455 }
456
457 return list;
458 }
459
460
471 public DLSync findByC_M_R_First(long companyId, long modifiedDate,
472 long repositoryId, OrderByComparator orderByComparator)
473 throws NoSuchSyncException, SystemException {
474 DLSync dlSync = fetchByC_M_R_First(companyId, modifiedDate,
475 repositoryId, orderByComparator);
476
477 if (dlSync != null) {
478 return dlSync;
479 }
480
481 StringBundler msg = new StringBundler(8);
482
483 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
484
485 msg.append("companyId=");
486 msg.append(companyId);
487
488 msg.append(", modifiedDate=");
489 msg.append(modifiedDate);
490
491 msg.append(", repositoryId=");
492 msg.append(repositoryId);
493
494 msg.append(StringPool.CLOSE_CURLY_BRACE);
495
496 throw new NoSuchSyncException(msg.toString());
497 }
498
499
509 public DLSync fetchByC_M_R_First(long companyId, long modifiedDate,
510 long repositoryId, OrderByComparator orderByComparator)
511 throws SystemException {
512 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
513 0, 1, orderByComparator);
514
515 if (!list.isEmpty()) {
516 return list.get(0);
517 }
518
519 return null;
520 }
521
522
533 public DLSync findByC_M_R_Last(long companyId, long modifiedDate,
534 long repositoryId, OrderByComparator orderByComparator)
535 throws NoSuchSyncException, SystemException {
536 DLSync dlSync = fetchByC_M_R_Last(companyId, modifiedDate,
537 repositoryId, orderByComparator);
538
539 if (dlSync != null) {
540 return dlSync;
541 }
542
543 StringBundler msg = new StringBundler(8);
544
545 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
546
547 msg.append("companyId=");
548 msg.append(companyId);
549
550 msg.append(", modifiedDate=");
551 msg.append(modifiedDate);
552
553 msg.append(", repositoryId=");
554 msg.append(repositoryId);
555
556 msg.append(StringPool.CLOSE_CURLY_BRACE);
557
558 throw new NoSuchSyncException(msg.toString());
559 }
560
561
571 public DLSync fetchByC_M_R_Last(long companyId, long modifiedDate,
572 long repositoryId, OrderByComparator orderByComparator)
573 throws SystemException {
574 int count = countByC_M_R(companyId, modifiedDate, repositoryId);
575
576 List<DLSync> list = findByC_M_R(companyId, modifiedDate, repositoryId,
577 count - 1, count, orderByComparator);
578
579 if (!list.isEmpty()) {
580 return list.get(0);
581 }
582
583 return null;
584 }
585
586
598 public DLSync[] findByC_M_R_PrevAndNext(long syncId, long companyId,
599 long modifiedDate, long repositoryId,
600 OrderByComparator orderByComparator)
601 throws NoSuchSyncException, SystemException {
602 DLSync dlSync = findByPrimaryKey(syncId);
603
604 Session session = null;
605
606 try {
607 session = openSession();
608
609 DLSync[] array = new DLSyncImpl[3];
610
611 array[0] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
612 modifiedDate, repositoryId, orderByComparator, true);
613
614 array[1] = dlSync;
615
616 array[2] = getByC_M_R_PrevAndNext(session, dlSync, companyId,
617 modifiedDate, repositoryId, orderByComparator, false);
618
619 return array;
620 }
621 catch (Exception e) {
622 throw processException(e);
623 }
624 finally {
625 closeSession(session);
626 }
627 }
628
629 protected DLSync getByC_M_R_PrevAndNext(Session session, DLSync dlSync,
630 long companyId, long modifiedDate, long repositoryId,
631 OrderByComparator orderByComparator, boolean previous) {
632 StringBundler query = null;
633
634 if (orderByComparator != null) {
635 query = new StringBundler(6 +
636 (orderByComparator.getOrderByFields().length * 6));
637 }
638 else {
639 query = new StringBundler(3);
640 }
641
642 query.append(_SQL_SELECT_DLSYNC_WHERE);
643
644 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
645
646 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
647
648 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
649
650 if (orderByComparator != null) {
651 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
652
653 if (orderByConditionFields.length > 0) {
654 query.append(WHERE_AND);
655 }
656
657 for (int i = 0; i < orderByConditionFields.length; i++) {
658 query.append(_ORDER_BY_ENTITY_ALIAS);
659 query.append(orderByConditionFields[i]);
660
661 if ((i + 1) < orderByConditionFields.length) {
662 if (orderByComparator.isAscending() ^ previous) {
663 query.append(WHERE_GREATER_THAN_HAS_NEXT);
664 }
665 else {
666 query.append(WHERE_LESSER_THAN_HAS_NEXT);
667 }
668 }
669 else {
670 if (orderByComparator.isAscending() ^ previous) {
671 query.append(WHERE_GREATER_THAN);
672 }
673 else {
674 query.append(WHERE_LESSER_THAN);
675 }
676 }
677 }
678
679 query.append(ORDER_BY_CLAUSE);
680
681 String[] orderByFields = orderByComparator.getOrderByFields();
682
683 for (int i = 0; i < orderByFields.length; i++) {
684 query.append(_ORDER_BY_ENTITY_ALIAS);
685 query.append(orderByFields[i]);
686
687 if ((i + 1) < orderByFields.length) {
688 if (orderByComparator.isAscending() ^ previous) {
689 query.append(ORDER_BY_ASC_HAS_NEXT);
690 }
691 else {
692 query.append(ORDER_BY_DESC_HAS_NEXT);
693 }
694 }
695 else {
696 if (orderByComparator.isAscending() ^ previous) {
697 query.append(ORDER_BY_ASC);
698 }
699 else {
700 query.append(ORDER_BY_DESC);
701 }
702 }
703 }
704 }
705 else {
706 query.append(DLSyncModelImpl.ORDER_BY_JPQL);
707 }
708
709 String sql = query.toString();
710
711 Query q = session.createQuery(sql);
712
713 q.setFirstResult(0);
714 q.setMaxResults(2);
715
716 QueryPos qPos = QueryPos.getInstance(q);
717
718 qPos.add(companyId);
719
720 qPos.add(modifiedDate);
721
722 qPos.add(repositoryId);
723
724 if (orderByComparator != null) {
725 Object[] values = orderByComparator.getOrderByConditionValues(dlSync);
726
727 for (Object value : values) {
728 qPos.add(value);
729 }
730 }
731
732 List<DLSync> list = q.list();
733
734 if (list.size() == 2) {
735 return list.get(1);
736 }
737 else {
738 return null;
739 }
740 }
741
742
750 public void removeByC_M_R(long companyId, long modifiedDate,
751 long repositoryId) throws SystemException {
752 for (DLSync dlSync : findByC_M_R(companyId, modifiedDate, repositoryId,
753 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
754 remove(dlSync);
755 }
756 }
757
758
767 public int countByC_M_R(long companyId, long modifiedDate, long repositoryId)
768 throws SystemException {
769 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_M_R;
770
771 Object[] finderArgs = new Object[] { companyId, modifiedDate, repositoryId };
772
773 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
774 this);
775
776 if (count == null) {
777 StringBundler query = new StringBundler(4);
778
779 query.append(_SQL_COUNT_DLSYNC_WHERE);
780
781 query.append(_FINDER_COLUMN_C_M_R_COMPANYID_2);
782
783 query.append(_FINDER_COLUMN_C_M_R_MODIFIEDDATE_2);
784
785 query.append(_FINDER_COLUMN_C_M_R_REPOSITORYID_2);
786
787 String sql = query.toString();
788
789 Session session = null;
790
791 try {
792 session = openSession();
793
794 Query q = session.createQuery(sql);
795
796 QueryPos qPos = QueryPos.getInstance(q);
797
798 qPos.add(companyId);
799
800 qPos.add(modifiedDate);
801
802 qPos.add(repositoryId);
803
804 count = (Long)q.uniqueResult();
805
806 FinderCacheUtil.putResult(finderPath, finderArgs, count);
807 }
808 catch (Exception e) {
809 FinderCacheUtil.removeResult(finderPath, finderArgs);
810
811 throw processException(e);
812 }
813 finally {
814 closeSession(session);
815 }
816 }
817
818 return count.intValue();
819 }
820
821 private static final String _FINDER_COLUMN_C_M_R_COMPANYID_2 = "dlSync.companyId = ? AND ";
822 private static final String _FINDER_COLUMN_C_M_R_MODIFIEDDATE_2 = "dlSync.modifiedDate > ? AND ";
823 private static final String _FINDER_COLUMN_C_M_R_REPOSITORYID_2 = "dlSync.repositoryId = ?";
824
825
830 public void cacheResult(DLSync dlSync) {
831 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
832 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
833
834 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID,
835 new Object[] { dlSync.getFileId() }, dlSync);
836
837 dlSync.resetOriginalValues();
838 }
839
840
845 public void cacheResult(List<DLSync> dlSyncs) {
846 for (DLSync dlSync : dlSyncs) {
847 if (EntityCacheUtil.getResult(
848 DLSyncModelImpl.ENTITY_CACHE_ENABLED, DLSyncImpl.class,
849 dlSync.getPrimaryKey()) == null) {
850 cacheResult(dlSync);
851 }
852 else {
853 dlSync.resetOriginalValues();
854 }
855 }
856 }
857
858
865 @Override
866 public void clearCache() {
867 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
868 CacheRegistryUtil.clear(DLSyncImpl.class.getName());
869 }
870
871 EntityCacheUtil.clearCache(DLSyncImpl.class.getName());
872
873 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
874 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
875 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
876 }
877
878
885 @Override
886 public void clearCache(DLSync dlSync) {
887 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
888 DLSyncImpl.class, dlSync.getPrimaryKey());
889
890 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
891 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
892
893 clearUniqueFindersCache(dlSync);
894 }
895
896 @Override
897 public void clearCache(List<DLSync> dlSyncs) {
898 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
899 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
900
901 for (DLSync dlSync : dlSyncs) {
902 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
903 DLSyncImpl.class, dlSync.getPrimaryKey());
904
905 clearUniqueFindersCache(dlSync);
906 }
907 }
908
909 protected void cacheUniqueFindersCache(DLSync dlSync) {
910 if (dlSync.isNew()) {
911 Object[] args = new Object[] { dlSync.getFileId() };
912
913 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID, args,
914 Long.valueOf(1));
915 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID, args, dlSync);
916 }
917 else {
918 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
919
920 if ((dlSyncModelImpl.getColumnBitmask() &
921 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
922 Object[] args = new Object[] { dlSync.getFileId() };
923
924 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEID, args,
925 Long.valueOf(1));
926 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FILEID, args,
927 dlSync);
928 }
929 }
930 }
931
932 protected void clearUniqueFindersCache(DLSync dlSync) {
933 DLSyncModelImpl dlSyncModelImpl = (DLSyncModelImpl)dlSync;
934
935 Object[] args = new Object[] { dlSync.getFileId() };
936
937 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
938 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
939
940 if ((dlSyncModelImpl.getColumnBitmask() &
941 FINDER_PATH_FETCH_BY_FILEID.getColumnBitmask()) != 0) {
942 args = new Object[] { dlSyncModelImpl.getOriginalFileId() };
943
944 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEID, args);
945 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FILEID, args);
946 }
947 }
948
949
955 public DLSync create(long syncId) {
956 DLSync dlSync = new DLSyncImpl();
957
958 dlSync.setNew(true);
959 dlSync.setPrimaryKey(syncId);
960
961 return dlSync;
962 }
963
964
972 public DLSync remove(long syncId)
973 throws NoSuchSyncException, SystemException {
974 return remove((Serializable)syncId);
975 }
976
977
985 @Override
986 public DLSync remove(Serializable primaryKey)
987 throws NoSuchSyncException, SystemException {
988 Session session = null;
989
990 try {
991 session = openSession();
992
993 DLSync dlSync = (DLSync)session.get(DLSyncImpl.class, primaryKey);
994
995 if (dlSync == null) {
996 if (_log.isWarnEnabled()) {
997 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
998 }
999
1000 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1001 primaryKey);
1002 }
1003
1004 return remove(dlSync);
1005 }
1006 catch (NoSuchSyncException nsee) {
1007 throw nsee;
1008 }
1009 catch (Exception e) {
1010 throw processException(e);
1011 }
1012 finally {
1013 closeSession(session);
1014 }
1015 }
1016
1017 @Override
1018 protected DLSync removeImpl(DLSync dlSync) throws SystemException {
1019 dlSync = toUnwrappedModel(dlSync);
1020
1021 Session session = null;
1022
1023 try {
1024 session = openSession();
1025
1026 if (!session.contains(dlSync)) {
1027 dlSync = (DLSync)session.get(DLSyncImpl.class,
1028 dlSync.getPrimaryKeyObj());
1029 }
1030
1031 if (dlSync != null) {
1032 session.delete(dlSync);
1033 }
1034 }
1035 catch (Exception e) {
1036 throw processException(e);
1037 }
1038 finally {
1039 closeSession(session);
1040 }
1041
1042 if (dlSync != null) {
1043 clearCache(dlSync);
1044 }
1045
1046 return dlSync;
1047 }
1048
1049 @Override
1050 public DLSync updateImpl(
1051 com.liferay.portlet.documentlibrary.model.DLSync dlSync)
1052 throws SystemException {
1053 dlSync = toUnwrappedModel(dlSync);
1054
1055 boolean isNew = dlSync.isNew();
1056
1057 Session session = null;
1058
1059 try {
1060 session = openSession();
1061
1062 if (dlSync.isNew()) {
1063 session.save(dlSync);
1064
1065 dlSync.setNew(false);
1066 }
1067 else {
1068 session.merge(dlSync);
1069 }
1070 }
1071 catch (Exception e) {
1072 throw processException(e);
1073 }
1074 finally {
1075 closeSession(session);
1076 }
1077
1078 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1079
1080 if (isNew || !DLSyncModelImpl.COLUMN_BITMASK_ENABLED) {
1081 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1082 }
1083
1084 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
1085 DLSyncImpl.class, dlSync.getPrimaryKey(), dlSync);
1086
1087 clearUniqueFindersCache(dlSync);
1088 cacheUniqueFindersCache(dlSync);
1089
1090 return dlSync;
1091 }
1092
1093 protected DLSync toUnwrappedModel(DLSync dlSync) {
1094 if (dlSync instanceof DLSyncImpl) {
1095 return dlSync;
1096 }
1097
1098 DLSyncImpl dlSyncImpl = new DLSyncImpl();
1099
1100 dlSyncImpl.setNew(dlSync.isNew());
1101 dlSyncImpl.setPrimaryKey(dlSync.getPrimaryKey());
1102
1103 dlSyncImpl.setSyncId(dlSync.getSyncId());
1104 dlSyncImpl.setCompanyId(dlSync.getCompanyId());
1105 dlSyncImpl.setCreateDate(dlSync.getCreateDate());
1106 dlSyncImpl.setModifiedDate(dlSync.getModifiedDate());
1107 dlSyncImpl.setFileId(dlSync.getFileId());
1108 dlSyncImpl.setFileUuid(dlSync.getFileUuid());
1109 dlSyncImpl.setRepositoryId(dlSync.getRepositoryId());
1110 dlSyncImpl.setParentFolderId(dlSync.getParentFolderId());
1111 dlSyncImpl.setName(dlSync.getName());
1112 dlSyncImpl.setDescription(dlSync.getDescription());
1113 dlSyncImpl.setEvent(dlSync.getEvent());
1114 dlSyncImpl.setType(dlSync.getType());
1115 dlSyncImpl.setVersion(dlSync.getVersion());
1116
1117 return dlSyncImpl;
1118 }
1119
1120
1128 @Override
1129 public DLSync findByPrimaryKey(Serializable primaryKey)
1130 throws NoSuchSyncException, SystemException {
1131 DLSync dlSync = fetchByPrimaryKey(primaryKey);
1132
1133 if (dlSync == null) {
1134 if (_log.isWarnEnabled()) {
1135 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1136 }
1137
1138 throw new NoSuchSyncException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1139 primaryKey);
1140 }
1141
1142 return dlSync;
1143 }
1144
1145
1153 public DLSync findByPrimaryKey(long syncId)
1154 throws NoSuchSyncException, SystemException {
1155 return findByPrimaryKey((Serializable)syncId);
1156 }
1157
1158
1165 @Override
1166 public DLSync fetchByPrimaryKey(Serializable primaryKey)
1167 throws SystemException {
1168 DLSync dlSync = (DLSync)EntityCacheUtil.getResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
1169 DLSyncImpl.class, primaryKey);
1170
1171 if (dlSync == _nullDLSync) {
1172 return null;
1173 }
1174
1175 if (dlSync == null) {
1176 Session session = null;
1177
1178 try {
1179 session = openSession();
1180
1181 dlSync = (DLSync)session.get(DLSyncImpl.class, primaryKey);
1182
1183 if (dlSync != null) {
1184 cacheResult(dlSync);
1185 }
1186 else {
1187 EntityCacheUtil.putResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
1188 DLSyncImpl.class, primaryKey, _nullDLSync);
1189 }
1190 }
1191 catch (Exception e) {
1192 EntityCacheUtil.removeResult(DLSyncModelImpl.ENTITY_CACHE_ENABLED,
1193 DLSyncImpl.class, primaryKey);
1194
1195 throw processException(e);
1196 }
1197 finally {
1198 closeSession(session);
1199 }
1200 }
1201
1202 return dlSync;
1203 }
1204
1205
1212 public DLSync fetchByPrimaryKey(long syncId) throws SystemException {
1213 return fetchByPrimaryKey((Serializable)syncId);
1214 }
1215
1216
1222 public List<DLSync> findAll() throws SystemException {
1223 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1224 }
1225
1226
1238 public List<DLSync> findAll(int start, int end) throws SystemException {
1239 return findAll(start, end, null);
1240 }
1241
1242
1255 public List<DLSync> findAll(int start, int end,
1256 OrderByComparator orderByComparator) throws SystemException {
1257 boolean pagination = true;
1258 FinderPath finderPath = null;
1259 Object[] finderArgs = null;
1260
1261 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1262 (orderByComparator == null)) {
1263 pagination = false;
1264 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1265 finderArgs = FINDER_ARGS_EMPTY;
1266 }
1267 else {
1268 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1269 finderArgs = new Object[] { start, end, orderByComparator };
1270 }
1271
1272 List<DLSync> list = (List<DLSync>)FinderCacheUtil.getResult(finderPath,
1273 finderArgs, this);
1274
1275 if (list == null) {
1276 StringBundler query = null;
1277 String sql = null;
1278
1279 if (orderByComparator != null) {
1280 query = new StringBundler(2 +
1281 (orderByComparator.getOrderByFields().length * 3));
1282
1283 query.append(_SQL_SELECT_DLSYNC);
1284
1285 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1286 orderByComparator);
1287
1288 sql = query.toString();
1289 }
1290 else {
1291 sql = _SQL_SELECT_DLSYNC;
1292
1293 if (pagination) {
1294 sql = sql.concat(DLSyncModelImpl.ORDER_BY_JPQL);
1295 }
1296 }
1297
1298 Session session = null;
1299
1300 try {
1301 session = openSession();
1302
1303 Query q = session.createQuery(sql);
1304
1305 if (!pagination) {
1306 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1307 end, false);
1308
1309 Collections.sort(list);
1310
1311 list = new UnmodifiableList<DLSync>(list);
1312 }
1313 else {
1314 list = (List<DLSync>)QueryUtil.list(q, getDialect(), start,
1315 end);
1316 }
1317
1318 cacheResult(list);
1319
1320 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1321 }
1322 catch (Exception e) {
1323 FinderCacheUtil.removeResult(finderPath, finderArgs);
1324
1325 throw processException(e);
1326 }
1327 finally {
1328 closeSession(session);
1329 }
1330 }
1331
1332 return list;
1333 }
1334
1335
1340 public void removeAll() throws SystemException {
1341 for (DLSync dlSync : findAll()) {
1342 remove(dlSync);
1343 }
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 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1367 FINDER_ARGS_EMPTY, count);
1368 }
1369 catch (Exception e) {
1370 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1371 FINDER_ARGS_EMPTY);
1372
1373 throw processException(e);
1374 }
1375 finally {
1376 closeSession(session);
1377 }
1378 }
1379
1380 return count.intValue();
1381 }
1382
1383
1386 public void afterPropertiesSet() {
1387 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1388 com.liferay.portal.util.PropsUtil.get(
1389 "value.object.listener.com.liferay.portlet.documentlibrary.model.DLSync")));
1390
1391 if (listenerClassNames.length > 0) {
1392 try {
1393 List<ModelListener<DLSync>> listenersList = new ArrayList<ModelListener<DLSync>>();
1394
1395 for (String listenerClassName : listenerClassNames) {
1396 listenersList.add((ModelListener<DLSync>)InstanceFactory.newInstance(
1397 listenerClassName));
1398 }
1399
1400 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1401 }
1402 catch (Exception e) {
1403 _log.error(e);
1404 }
1405 }
1406 }
1407
1408 public void destroy() {
1409 EntityCacheUtil.removeCache(DLSyncImpl.class.getName());
1410 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1411 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1412 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1413 }
1414
1415 private static final String _SQL_SELECT_DLSYNC = "SELECT dlSync FROM DLSync dlSync";
1416 private static final String _SQL_SELECT_DLSYNC_WHERE = "SELECT dlSync FROM DLSync dlSync WHERE ";
1417 private static final String _SQL_COUNT_DLSYNC = "SELECT COUNT(dlSync) FROM DLSync dlSync";
1418 private static final String _SQL_COUNT_DLSYNC_WHERE = "SELECT COUNT(dlSync) FROM DLSync dlSync WHERE ";
1419 private static final String _ORDER_BY_ENTITY_ALIAS = "dlSync.";
1420 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLSync exists with the primary key ";
1421 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLSync exists with the key {";
1422 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1423 private static Log _log = LogFactoryUtil.getLog(DLSyncPersistenceImpl.class);
1424 private static DLSync _nullDLSync = new DLSyncImpl() {
1425 @Override
1426 public Object clone() {
1427 return this;
1428 }
1429
1430 @Override
1431 public CacheModel<DLSync> toCacheModel() {
1432 return _nullDLSyncCacheModel;
1433 }
1434 };
1435
1436 private static CacheModel<DLSync> _nullDLSyncCacheModel = new CacheModel<DLSync>() {
1437 public DLSync toEntityModel() {
1438 return _nullDLSync;
1439 }
1440 };
1441 }