001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchWebDAVPropsException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.WebDAVProps;
038 import com.liferay.portal.model.impl.WebDAVPropsImpl;
039 import com.liferay.portal.model.impl.WebDAVPropsModelImpl;
040 import com.liferay.portal.service.ServiceContext;
041 import com.liferay.portal.service.ServiceContextThreadLocal;
042 import com.liferay.portal.service.persistence.CompanyProvider;
043 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
044 import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
045
046 import java.io.Serializable;
047
048 import java.util.Collections;
049 import java.util.Date;
050 import java.util.HashMap;
051 import java.util.HashSet;
052 import java.util.Iterator;
053 import java.util.List;
054 import java.util.Map;
055 import java.util.Set;
056
057
069 @ProviderType
070 public class WebDAVPropsPersistenceImpl extends BasePersistenceImpl<WebDAVProps>
071 implements WebDAVPropsPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = WebDAVPropsImpl.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_WITH_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
083 WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
086 WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
089 WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
092 WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
093 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
094 new String[] { Long.class.getName(), Long.class.getName() },
095 WebDAVPropsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
096 WebDAVPropsModelImpl.CLASSPK_COLUMN_BITMASK);
097 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
098 WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
100 new String[] { Long.class.getName(), Long.class.getName() });
101
102
110 @Override
111 public WebDAVProps findByC_C(long classNameId, long classPK)
112 throws NoSuchWebDAVPropsException {
113 WebDAVProps webDAVProps = fetchByC_C(classNameId, classPK);
114
115 if (webDAVProps == null) {
116 StringBundler msg = new StringBundler(6);
117
118 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
119
120 msg.append("classNameId=");
121 msg.append(classNameId);
122
123 msg.append(", classPK=");
124 msg.append(classPK);
125
126 msg.append(StringPool.CLOSE_CURLY_BRACE);
127
128 if (_log.isWarnEnabled()) {
129 _log.warn(msg.toString());
130 }
131
132 throw new NoSuchWebDAVPropsException(msg.toString());
133 }
134
135 return webDAVProps;
136 }
137
138
145 @Override
146 public WebDAVProps fetchByC_C(long classNameId, long classPK) {
147 return fetchByC_C(classNameId, classPK, true);
148 }
149
150
158 @Override
159 public WebDAVProps fetchByC_C(long classNameId, long classPK,
160 boolean retrieveFromCache) {
161 Object[] finderArgs = new Object[] { classNameId, classPK };
162
163 Object result = null;
164
165 if (retrieveFromCache) {
166 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
167 finderArgs, this);
168 }
169
170 if (result instanceof WebDAVProps) {
171 WebDAVProps webDAVProps = (WebDAVProps)result;
172
173 if ((classNameId != webDAVProps.getClassNameId()) ||
174 (classPK != webDAVProps.getClassPK())) {
175 result = null;
176 }
177 }
178
179 if (result == null) {
180 StringBundler query = new StringBundler(4);
181
182 query.append(_SQL_SELECT_WEBDAVPROPS_WHERE);
183
184 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
185
186 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
187
188 String sql = query.toString();
189
190 Session session = null;
191
192 try {
193 session = openSession();
194
195 Query q = session.createQuery(sql);
196
197 QueryPos qPos = QueryPos.getInstance(q);
198
199 qPos.add(classNameId);
200
201 qPos.add(classPK);
202
203 List<WebDAVProps> list = q.list();
204
205 if (list.isEmpty()) {
206 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
207 list);
208 }
209 else {
210 WebDAVProps webDAVProps = list.get(0);
211
212 result = webDAVProps;
213
214 cacheResult(webDAVProps);
215
216 if ((webDAVProps.getClassNameId() != classNameId) ||
217 (webDAVProps.getClassPK() != classPK)) {
218 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
219 finderArgs, webDAVProps);
220 }
221 }
222 }
223 catch (Exception e) {
224 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
225
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231 }
232
233 if (result instanceof List<?>) {
234 return null;
235 }
236 else {
237 return (WebDAVProps)result;
238 }
239 }
240
241
248 @Override
249 public WebDAVProps removeByC_C(long classNameId, long classPK)
250 throws NoSuchWebDAVPropsException {
251 WebDAVProps webDAVProps = findByC_C(classNameId, classPK);
252
253 return remove(webDAVProps);
254 }
255
256
263 @Override
264 public int countByC_C(long classNameId, long classPK) {
265 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
266
267 Object[] finderArgs = new Object[] { classNameId, classPK };
268
269 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
270
271 if (count == null) {
272 StringBundler query = new StringBundler(3);
273
274 query.append(_SQL_COUNT_WEBDAVPROPS_WHERE);
275
276 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
277
278 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
279
280 String sql = query.toString();
281
282 Session session = null;
283
284 try {
285 session = openSession();
286
287 Query q = session.createQuery(sql);
288
289 QueryPos qPos = QueryPos.getInstance(q);
290
291 qPos.add(classNameId);
292
293 qPos.add(classPK);
294
295 count = (Long)q.uniqueResult();
296
297 finderCache.putResult(finderPath, finderArgs, count);
298 }
299 catch (Exception e) {
300 finderCache.removeResult(finderPath, finderArgs);
301
302 throw processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307 }
308
309 return count.intValue();
310 }
311
312 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "webDAVProps.classNameId = ? AND ";
313 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "webDAVProps.classPK = ?";
314
315 public WebDAVPropsPersistenceImpl() {
316 setModelClass(WebDAVProps.class);
317 }
318
319
324 @Override
325 public void cacheResult(WebDAVProps webDAVProps) {
326 entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
327 WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps);
328
329 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
330 new Object[] { webDAVProps.getClassNameId(), webDAVProps.getClassPK() },
331 webDAVProps);
332
333 webDAVProps.resetOriginalValues();
334 }
335
336
341 @Override
342 public void cacheResult(List<WebDAVProps> webDAVPropses) {
343 for (WebDAVProps webDAVProps : webDAVPropses) {
344 if (entityCache.getResult(
345 WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
346 WebDAVPropsImpl.class, webDAVProps.getPrimaryKey()) == null) {
347 cacheResult(webDAVProps);
348 }
349 else {
350 webDAVProps.resetOriginalValues();
351 }
352 }
353 }
354
355
362 @Override
363 public void clearCache() {
364 entityCache.clearCache(WebDAVPropsImpl.class);
365
366 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
367 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
368 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
369 }
370
371
378 @Override
379 public void clearCache(WebDAVProps webDAVProps) {
380 entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
381 WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
382
383 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
384 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
385
386 clearUniqueFindersCache((WebDAVPropsModelImpl)webDAVProps);
387 }
388
389 @Override
390 public void clearCache(List<WebDAVProps> webDAVPropses) {
391 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
392 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
393
394 for (WebDAVProps webDAVProps : webDAVPropses) {
395 entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
396 WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
397
398 clearUniqueFindersCache((WebDAVPropsModelImpl)webDAVProps);
399 }
400 }
401
402 protected void cacheUniqueFindersCache(
403 WebDAVPropsModelImpl webDAVPropsModelImpl, boolean isNew) {
404 if (isNew) {
405 Object[] args = new Object[] {
406 webDAVPropsModelImpl.getClassNameId(),
407 webDAVPropsModelImpl.getClassPK()
408 };
409
410 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
411 Long.valueOf(1));
412 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
413 webDAVPropsModelImpl);
414 }
415 else {
416 if ((webDAVPropsModelImpl.getColumnBitmask() &
417 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
418 Object[] args = new Object[] {
419 webDAVPropsModelImpl.getClassNameId(),
420 webDAVPropsModelImpl.getClassPK()
421 };
422
423 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
424 Long.valueOf(1));
425 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
426 webDAVPropsModelImpl);
427 }
428 }
429 }
430
431 protected void clearUniqueFindersCache(
432 WebDAVPropsModelImpl webDAVPropsModelImpl) {
433 Object[] args = new Object[] {
434 webDAVPropsModelImpl.getClassNameId(),
435 webDAVPropsModelImpl.getClassPK()
436 };
437
438 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
439 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
440
441 if ((webDAVPropsModelImpl.getColumnBitmask() &
442 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
443 args = new Object[] {
444 webDAVPropsModelImpl.getOriginalClassNameId(),
445 webDAVPropsModelImpl.getOriginalClassPK()
446 };
447
448 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
449 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
450 }
451 }
452
453
459 @Override
460 public WebDAVProps create(long webDavPropsId) {
461 WebDAVProps webDAVProps = new WebDAVPropsImpl();
462
463 webDAVProps.setNew(true);
464 webDAVProps.setPrimaryKey(webDavPropsId);
465
466 webDAVProps.setCompanyId(companyProvider.getCompanyId());
467
468 return webDAVProps;
469 }
470
471
478 @Override
479 public WebDAVProps remove(long webDavPropsId)
480 throws NoSuchWebDAVPropsException {
481 return remove((Serializable)webDavPropsId);
482 }
483
484
491 @Override
492 public WebDAVProps remove(Serializable primaryKey)
493 throws NoSuchWebDAVPropsException {
494 Session session = null;
495
496 try {
497 session = openSession();
498
499 WebDAVProps webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
500 primaryKey);
501
502 if (webDAVProps == null) {
503 if (_log.isWarnEnabled()) {
504 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
505 }
506
507 throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
508 primaryKey);
509 }
510
511 return remove(webDAVProps);
512 }
513 catch (NoSuchWebDAVPropsException nsee) {
514 throw nsee;
515 }
516 catch (Exception e) {
517 throw processException(e);
518 }
519 finally {
520 closeSession(session);
521 }
522 }
523
524 @Override
525 protected WebDAVProps removeImpl(WebDAVProps webDAVProps) {
526 webDAVProps = toUnwrappedModel(webDAVProps);
527
528 Session session = null;
529
530 try {
531 session = openSession();
532
533 if (!session.contains(webDAVProps)) {
534 webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
535 webDAVProps.getPrimaryKeyObj());
536 }
537
538 if (webDAVProps != null) {
539 session.delete(webDAVProps);
540 }
541 }
542 catch (Exception e) {
543 throw processException(e);
544 }
545 finally {
546 closeSession(session);
547 }
548
549 if (webDAVProps != null) {
550 clearCache(webDAVProps);
551 }
552
553 return webDAVProps;
554 }
555
556 @Override
557 public WebDAVProps updateImpl(WebDAVProps webDAVProps) {
558 webDAVProps = toUnwrappedModel(webDAVProps);
559
560 boolean isNew = webDAVProps.isNew();
561
562 WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
563
564 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
565
566 Date now = new Date();
567
568 if (isNew && (webDAVProps.getCreateDate() == null)) {
569 if (serviceContext == null) {
570 webDAVProps.setCreateDate(now);
571 }
572 else {
573 webDAVProps.setCreateDate(serviceContext.getCreateDate(now));
574 }
575 }
576
577 if (!webDAVPropsModelImpl.hasSetModifiedDate()) {
578 if (serviceContext == null) {
579 webDAVProps.setModifiedDate(now);
580 }
581 else {
582 webDAVProps.setModifiedDate(serviceContext.getModifiedDate(now));
583 }
584 }
585
586 Session session = null;
587
588 try {
589 session = openSession();
590
591 if (webDAVProps.isNew()) {
592 session.save(webDAVProps);
593
594 webDAVProps.setNew(false);
595 }
596 else {
597 webDAVProps = (WebDAVProps)session.merge(webDAVProps);
598 }
599 }
600 catch (Exception e) {
601 throw processException(e);
602 }
603 finally {
604 closeSession(session);
605 }
606
607 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
608
609 if (isNew || !WebDAVPropsModelImpl.COLUMN_BITMASK_ENABLED) {
610 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
611 }
612
613 entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
614 WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps,
615 false);
616
617 clearUniqueFindersCache(webDAVPropsModelImpl);
618 cacheUniqueFindersCache(webDAVPropsModelImpl, isNew);
619
620 webDAVProps.resetOriginalValues();
621
622 return webDAVProps;
623 }
624
625 protected WebDAVProps toUnwrappedModel(WebDAVProps webDAVProps) {
626 if (webDAVProps instanceof WebDAVPropsImpl) {
627 return webDAVProps;
628 }
629
630 WebDAVPropsImpl webDAVPropsImpl = new WebDAVPropsImpl();
631
632 webDAVPropsImpl.setNew(webDAVProps.isNew());
633 webDAVPropsImpl.setPrimaryKey(webDAVProps.getPrimaryKey());
634
635 webDAVPropsImpl.setMvccVersion(webDAVProps.getMvccVersion());
636 webDAVPropsImpl.setWebDavPropsId(webDAVProps.getWebDavPropsId());
637 webDAVPropsImpl.setCompanyId(webDAVProps.getCompanyId());
638 webDAVPropsImpl.setCreateDate(webDAVProps.getCreateDate());
639 webDAVPropsImpl.setModifiedDate(webDAVProps.getModifiedDate());
640 webDAVPropsImpl.setClassNameId(webDAVProps.getClassNameId());
641 webDAVPropsImpl.setClassPK(webDAVProps.getClassPK());
642 webDAVPropsImpl.setProps(webDAVProps.getProps());
643
644 return webDAVPropsImpl;
645 }
646
647
654 @Override
655 public WebDAVProps findByPrimaryKey(Serializable primaryKey)
656 throws NoSuchWebDAVPropsException {
657 WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
658
659 if (webDAVProps == null) {
660 if (_log.isWarnEnabled()) {
661 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
662 }
663
664 throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
665 primaryKey);
666 }
667
668 return webDAVProps;
669 }
670
671
678 @Override
679 public WebDAVProps findByPrimaryKey(long webDavPropsId)
680 throws NoSuchWebDAVPropsException {
681 return findByPrimaryKey((Serializable)webDavPropsId);
682 }
683
684
690 @Override
691 public WebDAVProps fetchByPrimaryKey(Serializable primaryKey) {
692 WebDAVProps webDAVProps = (WebDAVProps)entityCache.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
693 WebDAVPropsImpl.class, primaryKey);
694
695 if (webDAVProps == _nullWebDAVProps) {
696 return null;
697 }
698
699 if (webDAVProps == null) {
700 Session session = null;
701
702 try {
703 session = openSession();
704
705 webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
706 primaryKey);
707
708 if (webDAVProps != null) {
709 cacheResult(webDAVProps);
710 }
711 else {
712 entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
713 WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
714 }
715 }
716 catch (Exception e) {
717 entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
718 WebDAVPropsImpl.class, primaryKey);
719
720 throw processException(e);
721 }
722 finally {
723 closeSession(session);
724 }
725 }
726
727 return webDAVProps;
728 }
729
730
736 @Override
737 public WebDAVProps fetchByPrimaryKey(long webDavPropsId) {
738 return fetchByPrimaryKey((Serializable)webDavPropsId);
739 }
740
741 @Override
742 public Map<Serializable, WebDAVProps> fetchByPrimaryKeys(
743 Set<Serializable> primaryKeys) {
744 if (primaryKeys.isEmpty()) {
745 return Collections.emptyMap();
746 }
747
748 Map<Serializable, WebDAVProps> map = new HashMap<Serializable, WebDAVProps>();
749
750 if (primaryKeys.size() == 1) {
751 Iterator<Serializable> iterator = primaryKeys.iterator();
752
753 Serializable primaryKey = iterator.next();
754
755 WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
756
757 if (webDAVProps != null) {
758 map.put(primaryKey, webDAVProps);
759 }
760
761 return map;
762 }
763
764 Set<Serializable> uncachedPrimaryKeys = null;
765
766 for (Serializable primaryKey : primaryKeys) {
767 WebDAVProps webDAVProps = (WebDAVProps)entityCache.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
768 WebDAVPropsImpl.class, primaryKey);
769
770 if (webDAVProps == null) {
771 if (uncachedPrimaryKeys == null) {
772 uncachedPrimaryKeys = new HashSet<Serializable>();
773 }
774
775 uncachedPrimaryKeys.add(primaryKey);
776 }
777 else {
778 map.put(primaryKey, webDAVProps);
779 }
780 }
781
782 if (uncachedPrimaryKeys == null) {
783 return map;
784 }
785
786 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
787 1);
788
789 query.append(_SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN);
790
791 for (Serializable primaryKey : uncachedPrimaryKeys) {
792 query.append(String.valueOf(primaryKey));
793
794 query.append(StringPool.COMMA);
795 }
796
797 query.setIndex(query.index() - 1);
798
799 query.append(StringPool.CLOSE_PARENTHESIS);
800
801 String sql = query.toString();
802
803 Session session = null;
804
805 try {
806 session = openSession();
807
808 Query q = session.createQuery(sql);
809
810 for (WebDAVProps webDAVProps : (List<WebDAVProps>)q.list()) {
811 map.put(webDAVProps.getPrimaryKeyObj(), webDAVProps);
812
813 cacheResult(webDAVProps);
814
815 uncachedPrimaryKeys.remove(webDAVProps.getPrimaryKeyObj());
816 }
817
818 for (Serializable primaryKey : uncachedPrimaryKeys) {
819 entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
820 WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
821 }
822 }
823 catch (Exception e) {
824 throw processException(e);
825 }
826 finally {
827 closeSession(session);
828 }
829
830 return map;
831 }
832
833
838 @Override
839 public List<WebDAVProps> findAll() {
840 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
841 }
842
843
854 @Override
855 public List<WebDAVProps> findAll(int start, int end) {
856 return findAll(start, end, null);
857 }
858
859
871 @Override
872 public List<WebDAVProps> findAll(int start, int end,
873 OrderByComparator<WebDAVProps> orderByComparator) {
874 return findAll(start, end, orderByComparator, true);
875 }
876
877
890 @Override
891 public List<WebDAVProps> findAll(int start, int end,
892 OrderByComparator<WebDAVProps> orderByComparator,
893 boolean retrieveFromCache) {
894 boolean pagination = true;
895 FinderPath finderPath = null;
896 Object[] finderArgs = null;
897
898 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
899 (orderByComparator == null)) {
900 pagination = false;
901 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
902 finderArgs = FINDER_ARGS_EMPTY;
903 }
904 else {
905 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
906 finderArgs = new Object[] { start, end, orderByComparator };
907 }
908
909 List<WebDAVProps> list = null;
910
911 if (retrieveFromCache) {
912 list = (List<WebDAVProps>)finderCache.getResult(finderPath,
913 finderArgs, this);
914 }
915
916 if (list == null) {
917 StringBundler query = null;
918 String sql = null;
919
920 if (orderByComparator != null) {
921 query = new StringBundler(2 +
922 (orderByComparator.getOrderByFields().length * 3));
923
924 query.append(_SQL_SELECT_WEBDAVPROPS);
925
926 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
927 orderByComparator);
928
929 sql = query.toString();
930 }
931 else {
932 sql = _SQL_SELECT_WEBDAVPROPS;
933
934 if (pagination) {
935 sql = sql.concat(WebDAVPropsModelImpl.ORDER_BY_JPQL);
936 }
937 }
938
939 Session session = null;
940
941 try {
942 session = openSession();
943
944 Query q = session.createQuery(sql);
945
946 if (!pagination) {
947 list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
948 start, end, false);
949
950 Collections.sort(list);
951
952 list = Collections.unmodifiableList(list);
953 }
954 else {
955 list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
956 start, end);
957 }
958
959 cacheResult(list);
960
961 finderCache.putResult(finderPath, finderArgs, list);
962 }
963 catch (Exception e) {
964 finderCache.removeResult(finderPath, finderArgs);
965
966 throw processException(e);
967 }
968 finally {
969 closeSession(session);
970 }
971 }
972
973 return list;
974 }
975
976
980 @Override
981 public void removeAll() {
982 for (WebDAVProps webDAVProps : findAll()) {
983 remove(webDAVProps);
984 }
985 }
986
987
992 @Override
993 public int countAll() {
994 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
995 FINDER_ARGS_EMPTY, this);
996
997 if (count == null) {
998 Session session = null;
999
1000 try {
1001 session = openSession();
1002
1003 Query q = session.createQuery(_SQL_COUNT_WEBDAVPROPS);
1004
1005 count = (Long)q.uniqueResult();
1006
1007 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1008 count);
1009 }
1010 catch (Exception e) {
1011 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1012 FINDER_ARGS_EMPTY);
1013
1014 throw processException(e);
1015 }
1016 finally {
1017 closeSession(session);
1018 }
1019 }
1020
1021 return count.intValue();
1022 }
1023
1024 @Override
1025 protected Map<String, Integer> getTableColumnsMap() {
1026 return WebDAVPropsModelImpl.TABLE_COLUMNS_MAP;
1027 }
1028
1029
1032 public void afterPropertiesSet() {
1033 }
1034
1035 public void destroy() {
1036 entityCache.removeCache(WebDAVPropsImpl.class.getName());
1037 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1038 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1039 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1040 }
1041
1042 @BeanReference(type = CompanyProviderWrapper.class)
1043 protected CompanyProvider companyProvider;
1044 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1045 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1046 private static final String _SQL_SELECT_WEBDAVPROPS = "SELECT webDAVProps FROM WebDAVProps webDAVProps";
1047 private static final String _SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE webDavPropsId IN (";
1048 private static final String _SQL_SELECT_WEBDAVPROPS_WHERE = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE ";
1049 private static final String _SQL_COUNT_WEBDAVPROPS = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps";
1050 private static final String _SQL_COUNT_WEBDAVPROPS_WHERE = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps WHERE ";
1051 private static final String _ORDER_BY_ENTITY_ALIAS = "webDAVProps.";
1052 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WebDAVProps exists with the primary key ";
1053 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WebDAVProps exists with the key {";
1054 private static final Log _log = LogFactoryUtil.getLog(WebDAVPropsPersistenceImpl.class);
1055 private static final WebDAVProps _nullWebDAVProps = new WebDAVPropsImpl() {
1056 @Override
1057 public Object clone() {
1058 return this;
1059 }
1060
1061 @Override
1062 public CacheModel<WebDAVProps> toCacheModel() {
1063 return _nullWebDAVPropsCacheModel;
1064 }
1065 };
1066
1067 private static final CacheModel<WebDAVProps> _nullWebDAVPropsCacheModel = new NullCacheModel();
1068
1069 private static class NullCacheModel implements CacheModel<WebDAVProps>,
1070 MVCCModel {
1071 @Override
1072 public long getMvccVersion() {
1073 return -1;
1074 }
1075
1076 @Override
1077 public void setMvccVersion(long mvccVersion) {
1078 }
1079
1080 @Override
1081 public WebDAVProps toEntityModel() {
1082 return _nullWebDAVProps;
1083 }
1084 }
1085 }