DATACOUCH-78 - Adapted to changes in BeanWrapper generics.

Also adapted to API change in RepositoryProxyPostProcessor.

Related issues: DATACMNS-468, DATACMNS-464.
This commit is contained in:
Oliver Gierke
2014-03-19 10:00:25 +01:00
parent 80710ef75f
commit 629bc1d275
3 changed files with 27 additions and 29 deletions

View File

@@ -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<PersistentEntity<Object, ?>, Object> beanWrapper = BeanWrapper.create(readEntity,
couchbaseConverter.getConversionService());
final BeanWrapper<Object> 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<PersistentEntity<Object, ?>, Object> beanWrapper = BeanWrapper.create(objectToSave,
couchbaseConverter.getConversionService());
final BeanWrapper<Object> 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<Object>(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<PersistentEntity<Object,?>, Object> beanWrapper = BeanWrapper.create(objectToInsert,
couchbaseConverter.getConversionService());
final BeanWrapper<Object> 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<PersistentEntity<Object, ?>, Object> beanWrapper = BeanWrapper.create(objectToUpdate,
couchbaseConverter.getConversionService());
final BeanWrapper<Object> 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<Object>(objectToUpdate));
final CouchbaseDocument converted = new CouchbaseDocument();

View File

@@ -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<? extends CouchbasePersistentEntity<?>,
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<CouchbasePersistentEntity<R>, R> wrapper = BeanWrapper.create(instance, conversionService);
final BeanWrapper<R> wrapper = BeanWrapper.create(instance, conversionService);
final R result = wrapper.getBean();
entity.doWithProperties(new PropertyHandler<CouchbasePersistentProperty>() {
@@ -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<CouchbasePersistentEntity<Object>, Object> wrapper = BeanWrapper.create(source,
conversionService);
final BeanWrapper<Object> 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<CouchbasePersistentProperty> 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);
}

View File

@@ -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<Map<Object, Object>> VIEW_METADATA = new NamedThreadLocal<Map<Object, Object>>("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);
}