From 629bc1d275db6452d34f11420a1ce47121df958a Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 19 Mar 2014 10:00:25 +0100 Subject: [PATCH] DATACOUCH-78 - Adapted to changes in BeanWrapper generics. Also adapted to API change in RepositoryProxyPostProcessor. Related issues: DATACMNS-468, DATACMNS-464. --- .../couchbase/core/CouchbaseTemplate.java | 22 ++++++++----------- .../convert/MappingCouchbaseConverter.java | 21 +++++++----------- .../repository/support/ViewPostProcessor.java | 13 ++++++++--- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java index e8631d6f..4439f47c 100644 --- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java +++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,6 @@ import org.springframework.data.couchbase.core.mapping.event.BeforeConvertEvent; import org.springframework.data.couchbase.core.mapping.event.BeforeDeleteEvent; import org.springframework.data.couchbase.core.mapping.event.BeforeSaveEvent; import org.springframework.data.couchbase.core.mapping.event.CouchbaseMappingEvent; -import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.BeanWrapper; @@ -63,6 +62,7 @@ import java.util.concurrent.TimeoutException; /** * @author Michael Nitschinger + * @author Oliver Gierke */ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventPublisherAware { @@ -185,8 +185,7 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP Object readEntity = couchbaseConverter.read(entityClass, (CouchbaseDocument) translateDecode( (String) result.getValue(), converted)); - final BeanWrapper, Object> beanWrapper = BeanWrapper.create(readEntity, - couchbaseConverter.getConversionService()); + final BeanWrapper beanWrapper = BeanWrapper.create(readEntity, couchbaseConverter.getConversionService()); CouchbasePersistentEntity persistentEntity = mappingContext.getPersistentEntity(readEntity.getClass()); if (persistentEntity.hasVersionProperty()) { beanWrapper.setProperty(persistentEntity.getVersionProperty(), result.getCas()); @@ -287,11 +286,10 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP public void save(Object objectToSave, final PersistTo persistTo, final ReplicateTo replicateTo) { ensureNotIterable(objectToSave); - final BeanWrapper, Object> beanWrapper = BeanWrapper.create(objectToSave, - couchbaseConverter.getConversionService()); + final BeanWrapper beanWrapper = BeanWrapper.create(objectToSave, couchbaseConverter.getConversionService()); CouchbasePersistentEntity persistentEntity = mappingContext.getPersistentEntity(objectToSave.getClass()); final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty(); - final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class, true) : null; + final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class) : null; maybeEmitEvent(new BeforeConvertEvent(objectToSave)); final CouchbaseDocument converted = new CouchbaseDocument(); @@ -338,11 +336,10 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP ensureNotIterable(objectToInsert); final CouchbasePersistentEntity persistentEntity = mappingContext.getPersistentEntity(objectToInsert.getClass()); - final BeanWrapper, Object> beanWrapper = BeanWrapper.create(objectToInsert, - couchbaseConverter.getConversionService()); + final BeanWrapper beanWrapper = BeanWrapper.create(objectToInsert, couchbaseConverter.getConversionService()); if (persistentEntity != null && persistentEntity.hasVersionProperty()) { - final Long version = beanWrapper.getProperty(persistentEntity.getVersionProperty(), Long.class, true); + final Long version = beanWrapper.getProperty(persistentEntity.getVersionProperty(), Long.class); if (version == 0) { beanWrapper.setProperty(persistentEntity.getVersionProperty(), 0); } @@ -384,11 +381,10 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationEventP public void update(Object objectToUpdate, final PersistTo persistTo, final ReplicateTo replicateTo) { ensureNotIterable(objectToUpdate); - final BeanWrapper, Object> beanWrapper = BeanWrapper.create(objectToUpdate, - couchbaseConverter.getConversionService()); + final BeanWrapper beanWrapper = BeanWrapper.create(objectToUpdate, couchbaseConverter.getConversionService()); CouchbasePersistentEntity persistentEntity = mappingContext.getPersistentEntity(objectToUpdate.getClass()); final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty(); - final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class, true) : null; + final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class) : null; maybeEmitEvent(new BeforeConvertEvent(objectToUpdate)); final CouchbaseDocument converted = new CouchbaseDocument(); diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index f52255d5..4ea9e60d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,7 @@ import java.util.*; * consumable database represenation. * * @author Michael Nitschinger + * @author Oliver Gierke */ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements ApplicationContextAware { @@ -61,11 +62,6 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter protected final MappingContext, CouchbasePersistentProperty> mappingContext; - /** - * Always use field access only. - */ - protected boolean useFieldAccessOnly = true; - /** * The Couchbase specific type mapper in use. */ @@ -162,7 +158,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); R instance = instantiator.createInstance(entity, provider); - final BeanWrapper, R> wrapper = BeanWrapper.create(instance, conversionService); + final BeanWrapper wrapper = BeanWrapper.create(instance, conversionService); final R result = wrapper.getBean(); entity.doWithProperties(new PropertyHandler() { @@ -172,7 +168,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return; } Object obj = prop.isIdProperty() ? source.getId() : getValueInternal(prop, source, result); - wrapper.setProperty(prop, obj, useFieldAccessOnly); + wrapper.setProperty(prop, obj); } private boolean doesPropertyExistInSource(final CouchbasePersistentProperty property) { @@ -381,13 +377,12 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter throw new MappingException("No mapping metadata found for entity of type " + source.getClass().getName()); } - final BeanWrapper, Object> wrapper = BeanWrapper.create(source, - conversionService); + final BeanWrapper wrapper = BeanWrapper.create(source, conversionService); final CouchbasePersistentProperty idProperty = entity.getIdProperty(); final CouchbasePersistentProperty versionProperty = entity.getVersionProperty(); if (idProperty != null && target.getId() == null) { - String id = wrapper.getProperty(idProperty, String.class, useFieldAccessOnly); + String id = wrapper.getProperty(idProperty, String.class); target.setId(id); } target.setExpiration(entity.getExpiry()); @@ -399,7 +394,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return; } - Object propertyObj = wrapper.getProperty(prop, prop.getType(), useFieldAccessOnly); + Object propertyObj = wrapper.getProperty(prop, prop.getType()); if (null != propertyObj) { if (!conversions.isSimpleType(propertyObj.getClass())) { writePropertyInternal(propertyObj, target, prop); @@ -415,7 +410,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter public void doWithAssociation(final Association association) { CouchbasePersistentProperty inverseProp = association.getInverse(); Class type = inverseProp.getType(); - Object propertyObj = wrapper.getProperty(inverseProp, type, useFieldAccessOnly); + Object propertyObj = wrapper.getProperty(inverseProp, type); if (null != propertyObj) { writePropertyInternal(propertyObj, target, inverseProp); } diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java b/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java index da6c54ce..4dbe0f69 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/ViewPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.core.NamedThreadLocal; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.couchbase.core.view.View; +import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.support.RepositoryProxyPostProcessor; import java.lang.reflect.Method; @@ -34,7 +35,8 @@ import java.util.Map; * invoked method. This is necessary to allow redeclaration of CRUD methods in repository interfaces and configure * view information on them. * - * @author David Harrigan. + * @author David Harrigan + * @author Oliver Gierke */ public enum ViewPostProcessor implements RepositoryProxyPostProcessor { @@ -42,8 +44,13 @@ public enum ViewPostProcessor implements RepositoryProxyPostProcessor { private static final ThreadLocal> VIEW_METADATA = new NamedThreadLocal>("View Metadata"); + /* + * (non-Javadoc) + * @see org.springframework.data.repository.core.support.RepositoryProxyPostProcessor#postProcess(org.springframework.aop.framework.ProxyFactory, org.springframework.data.repository.core.RepositoryInformation) + */ @Override - public void postProcess(final ProxyFactory factory) { + public void postProcess(ProxyFactory factory, RepositoryInformation repositoryInformation) { + factory.addAdvice(ExposeInvocationInterceptor.INSTANCE); factory.addAdvice(ViewInterceptor.INSTANCE); }