SGF-429 - GemfirePersistentProperty considers a BigDecimal property an entity.

Additional changes and refactoring inspired by Spring Data MongoDB custom SimpleTypeHolder.
This commit is contained in:
John Blum
2015-10-05 22:04:16 -07:00
parent 6113bfbea1
commit 2344eb521d
4 changed files with 121 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.mapping;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import org.springframework.data.gemfire.mapping.model.GemfireSimpleTypeHolder;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.TypeInformation;
@@ -29,6 +30,18 @@ import org.springframework.data.util.TypeInformation;
*/
public class GemfireMappingContext extends AbstractMappingContext<GemfirePersistentEntity<?>, GemfirePersistentProperty> {
/**
* Constructs a GemfireMappingContext with a GemfireSimpleTypeHolder.
*
* @see org.springframework.data.gemfire.mapping.model.GemfireSimpleTypeHolder
*/
public GemfireMappingContext() {
// Technically, the following call is not Thread-safe (the "this" reference escapes), but then MappingContext
// makes no Thread-safety guarantees, even though, most likely, and especially in GemFire's case,
// the MappingContext will be used in a highly concurrent context (modeled after SD MongoDB for consistency)!
setSimpleTypeHolder(new GemfireSimpleTypeHolder());
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation)

View File

@@ -32,6 +32,12 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
*/
public class GemfirePersistentProperty extends AnnotationBasedPersistentProperty<GemfirePersistentProperty> {
/* (non-Javadoc) */
private static SimpleTypeHolder resolveSimpleTypeHolder(SimpleTypeHolder source) {
return (source instanceof GemfireSimpleTypeHolder ? source
: (source != null ? new GemfireSimpleTypeHolder(source) : new GemfireSimpleTypeHolder()));
}
/**
* Constructs an instance of the GemfirePersistentProperty with entity information.
*
@@ -42,7 +48,7 @@ public class GemfirePersistentProperty extends AnnotationBasedPersistentProperty
*/
public GemfirePersistentProperty(Field field, PropertyDescriptor propertyDescriptor,
PersistentEntity<?, GemfirePersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
super(field, propertyDescriptor, owner, new GemfireSimpleTypeHolder(simpleTypeHolder));
super(field, propertyDescriptor, owner, resolveSimpleTypeHolder(simpleTypeHolder));
}
/*

View File

@@ -34,6 +34,8 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
@SuppressWarnings("unused")
public class GemfireSimpleTypeHolder extends SimpleTypeHolder {
private static final boolean REGISTER_DEFAULTS = true;
protected static final Set<Class<?>> CUSTOM_SIMPLE_TYPES = new HashSet<Class<?>>(2);
static {
@@ -41,6 +43,15 @@ public class GemfireSimpleTypeHolder extends SimpleTypeHolder {
CUSTOM_SIMPLE_TYPES.add(BigInteger.class);
}
/**
* Constructs an instance of GemfireSimpleTypeHolder initialized with additional, custom simple types
* handled by GemFire along with register the default simple types.
* @see org.springframework.data.mapping.model.SimpleTypeHolder(Set, boolean)
*/
public GemfireSimpleTypeHolder() {
super(CUSTOM_SIMPLE_TYPES, REGISTER_DEFAULTS);
}
/**
* Constructs an instance of the GemfireSimpleTypeHolder initialized with a source {@link SimpleTypeHolder}.
*