SGF-640- Adapt to API changes in mapping subsystem.
This commit is contained in:
@@ -22,7 +22,6 @@ import static org.springframework.data.gemfire.util.ArrayUtils.defaultIfEmpty;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeMap;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
@@ -241,9 +240,7 @@ public class EntityDefinedRegionsConfiguration
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected GemfirePersistentEntity<?> getPersistentEntity(Class<?> persistentEntityType) {
|
||||
|
||||
return resolveMappingContext().getPersistentEntity(persistentEntityType).orElseThrow(
|
||||
() -> newIllegalStateException("PersistentEntity for type [%s] not found", persistentEntityType));
|
||||
return resolveMappingContext().getPersistentEntity(persistentEntityType);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@@ -529,9 +526,9 @@ public class EntityDefinedRegionsConfiguration
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Class<?> resolveIdType(GemfirePersistentEntity persistentEntity) {
|
||||
|
||||
return (Class<?>) persistentEntity.getIdProperty()
|
||||
return Optional.ofNullable(persistentEntity.getIdProperty())
|
||||
.map(idProperty -> ((GemfirePersistentProperty) idProperty).getActualType())
|
||||
.orElse(Object.class);
|
||||
.orElse((Class) Object.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
|
||||
@@ -137,17 +137,25 @@ public class IndexConfiguration extends EntityDefinedRegionsConfiguration {
|
||||
|
||||
localPersistentEntity.doWithProperties((PropertyHandler<GemfirePersistentProperty>) persistentProperty -> {
|
||||
|
||||
persistentProperty.findAnnotation(Id.class).ifPresent(idAnnotation ->
|
||||
registerIndexBeanDefinition(enableIndexingAttributes, localPersistentEntity, persistentProperty,
|
||||
IndexType.KEY, idAnnotation, registry));
|
||||
Optional<Id> idAnnotation = Optional.ofNullable(persistentProperty.findAnnotation(Id.class));
|
||||
|
||||
persistentProperty.findAnnotation(Indexed.class).ifPresent(indexedAnnotation ->
|
||||
idAnnotation.ifPresent(id ->
|
||||
registerIndexBeanDefinition(enableIndexingAttributes, localPersistentEntity, persistentProperty,
|
||||
indexedAnnotation.type(), indexedAnnotation, registry));
|
||||
IndexType.KEY, id, registry));
|
||||
|
||||
persistentProperty.findAnnotation(LuceneIndexed.class).ifPresent( luceneIndexAnnotation ->
|
||||
Optional<Indexed> indexedAnnotation =
|
||||
Optional.ofNullable(persistentProperty.findAnnotation(Indexed.class));
|
||||
|
||||
indexedAnnotation.ifPresent(indexed ->
|
||||
registerIndexBeanDefinition(enableIndexingAttributes, localPersistentEntity, persistentProperty,
|
||||
indexed.type(), indexed, registry));
|
||||
|
||||
Optional<LuceneIndexed> luceneIndexedAnnotation =
|
||||
Optional.ofNullable(persistentProperty.findAnnotation(LuceneIndexed.class));
|
||||
|
||||
luceneIndexedAnnotation.ifPresent(luceneIndexed ->
|
||||
registerLuceneIndexBeanDefinition(enableIndexingAttributes, localPersistentEntity,
|
||||
persistentProperty, luceneIndexAnnotation, registry));
|
||||
persistentProperty, luceneIndexed, registry));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.gemfire.mapping.annotation.Region;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -149,11 +149,10 @@ public class GemfirePersistentEntity<T> extends BasicPersistentEntity<T, Gemfire
|
||||
GemfirePersistentProperty property) {
|
||||
|
||||
if (property.isIdProperty()) {
|
||||
Optional<GemfirePersistentProperty> optionalIdProperty = getIdProperty();
|
||||
|
||||
if (optionalIdProperty.isPresent()) {
|
||||
GemfirePersistentProperty idProperty = getIdProperty().get();
|
||||
GemfirePersistentProperty idProperty = getIdProperty();
|
||||
|
||||
if (idProperty != null) {
|
||||
if (idProperty.isExplicitIdProperty()) {
|
||||
if (property.isExplicitIdProperty()) {
|
||||
throw new MappingException(String.format(
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.data.gemfire.mapping;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.pdx.PdxReader;
|
||||
import org.springframework.data.mapping.model.PropertyValueProvider;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -49,7 +47,7 @@ class GemfirePropertyValueProvider implements PropertyValueProvider<GemfirePersi
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<T> getPropertyValue(GemfirePersistentProperty property) {
|
||||
return Optional.ofNullable((T) reader.readField(property.getName()));
|
||||
public <T> T getPropertyValue(GemfirePersistentProperty property) {
|
||||
return (T) reader.readField(property.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.mapping;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -33,11 +30,11 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.convert.EntityInstantiator;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
|
||||
import org.springframework.data.mapping.model.SpELContext;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -185,21 +182,22 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw
|
||||
GemfirePersistentEntity<?> entity = getPersistentEntity(type);
|
||||
|
||||
Object instance = getInstantiatorFor(entity).createInstance(entity,
|
||||
new PersistentEntityParameterValueProvider<>(entity, new GemfirePropertyValueProvider(reader),
|
||||
Optional.empty()));
|
||||
new PersistentEntityParameterValueProvider<>(entity, new GemfirePropertyValueProvider(reader), null));
|
||||
|
||||
PersistentPropertyAccessor propertyAccessor =
|
||||
new ConvertingPropertyAccessor(entity.getPropertyAccessor(instance), getConversionService());
|
||||
|
||||
entity.doWithProperties((PropertyHandler<GemfirePersistentProperty>) persistentProperty -> {
|
||||
|
||||
if (!entity.isConstructorArgument(persistentProperty)) {
|
||||
|
||||
PdxSerializer customSerializer = getCustomSerializer(persistentProperty.getType());
|
||||
|
||||
Object value = null;
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("setting property [%1$s] for entity [%2$s] of type [%3$s] from PDX%4$s",
|
||||
log.debug(String.format("Setting property [%1$s] for entity [%2$s] of type [%3$s] from PDX%4$s",
|
||||
persistentProperty.getName(), instance, type, (customSerializer != null ?
|
||||
String.format(" using custom PdxSerializer [%1$s]", customSerializer) : "")));
|
||||
}
|
||||
@@ -209,10 +207,10 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw
|
||||
: reader.readField(persistentProperty.getName()));
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("with value [%1$s]", value));
|
||||
log.debug(String.format("... with value [%s]", value));
|
||||
}
|
||||
|
||||
propertyAccessor.setProperty(persistentProperty, Optional.ofNullable(value));
|
||||
propertyAccessor.setProperty(persistentProperty, value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MappingException(String.format(
|
||||
@@ -239,9 +237,10 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw
|
||||
new ConvertingPropertyAccessor(entity.getPropertyAccessor(value), getConversionService());
|
||||
|
||||
entity.doWithProperties((PropertyHandler<GemfirePersistentProperty>) persistentProperty -> {
|
||||
|
||||
PdxSerializer customSerializer = getCustomSerializer(persistentProperty.getType());
|
||||
|
||||
Optional<Object> propertyValue = null;
|
||||
Object propertyValue = null;
|
||||
|
||||
try {
|
||||
propertyValue = propertyAccessor.getProperty(persistentProperty);
|
||||
@@ -253,28 +252,27 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw
|
||||
}
|
||||
|
||||
if (customSerializer != null) {
|
||||
customSerializer.toData(propertyValue.orElse(null), writer);
|
||||
customSerializer.toData(propertyValue, writer);
|
||||
}
|
||||
else {
|
||||
writer.writeField(persistentProperty.getName(), propertyValue.orElse(null),
|
||||
writer.writeField(persistentProperty.getName(), propertyValue,
|
||||
(Class<Object>) persistentProperty.getType());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Object resolvedPropertyValue = (propertyValue != null ? propertyValue.orElse(null) : null);
|
||||
|
||||
throw new MappingException(String.format(
|
||||
"While serializing entity property [%1$s] value [%2$s] of type [%3$s] to PDX%4$s",
|
||||
persistentProperty.getName(), resolvedPropertyValue, value.getClass(),
|
||||
persistentProperty.getName(), propertyValue, value.getClass(),
|
||||
(customSerializer != null ? String.format(" using custom PdxSerializer [%1$s].",
|
||||
customSerializer.getClass().getName()) : ".")), e);
|
||||
}
|
||||
});
|
||||
|
||||
Optional<GemfirePersistentProperty> idProperty = entity.getIdProperty();
|
||||
GemfirePersistentProperty idProperty = entity.getIdProperty();
|
||||
|
||||
idProperty.ifPresent(gemfirePersistentProperty ->
|
||||
writer.markIdentityField(gemfirePersistentProperty.getName()));
|
||||
if (idProperty != null) {
|
||||
writer.markIdentityField(idProperty.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -326,7 +324,6 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw
|
||||
* @see #getMappingContext()
|
||||
*/
|
||||
protected GemfirePersistentEntity<?> getPersistentEntity(Class<?> entityType) {
|
||||
return getMappingContext().getPersistentEntity(entityType).orElseThrow(
|
||||
() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%]", entityType));
|
||||
return getMappingContext().getPersistentEntity(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.data.gemfire.mapping;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
@@ -74,10 +73,11 @@ public class Regions implements Iterable<Region<?, ?>> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Region<?, T> getRegion(Class<T> entityType) {
|
||||
|
||||
Assert.notNull(entityType, "Entity type must not be null");
|
||||
|
||||
String regionName = this.mappingContext.getPersistentEntity(entityType).map((entity) -> entity.getRegionName())
|
||||
.orElseGet(entityType::getSimpleName);
|
||||
String regionName = Optional.ofNullable(this.mappingContext.getPersistentEntity(entityType))
|
||||
.map(entity -> entity.getRegionName()).orElseGet(entityType::getSimpleName);
|
||||
|
||||
return (Region<?, T>) this.regions.get(regionName);
|
||||
}
|
||||
@@ -92,6 +92,7 @@ public class Regions implements Iterable<Region<?, ?>> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S, T> Region<S, T> getRegion(String namePath) {
|
||||
|
||||
Assert.hasText(namePath, "Region name/path is required");
|
||||
|
||||
return (Region<S, T>) this.regions.get(namePath);
|
||||
|
||||
@@ -67,9 +67,8 @@ public class GemfireQueryMethod extends QueryMethod {
|
||||
assertNonPagingQueryMethod(method);
|
||||
|
||||
this.method = method;
|
||||
this.entity = mappingContext.getPersistentEntity(getDomainClass()).orElseThrow(
|
||||
() -> new IllegalArgumentException(String.format("Failed to resolve PersistentEntity for type [%s]",
|
||||
getDomainClass())));
|
||||
|
||||
this.entity = mappingContext.getPersistentEntity(getDomainClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.data.gemfire.repository.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -84,9 +83,8 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, ID> GemfireEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
|
||||
GemfirePersistentEntity<T> entity = (GemfirePersistentEntity<T>) mappingContext.getPersistentEntity(domainClass)
|
||||
.orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]",
|
||||
domainClass));
|
||||
GemfirePersistentEntity<T> entity =
|
||||
(GemfirePersistentEntity<T>) mappingContext.getPersistentEntity(domainClass);
|
||||
|
||||
return new DefaultGemfireEntityInformation<>(entity);
|
||||
}
|
||||
@@ -108,9 +106,7 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport {
|
||||
|
||||
GemfireTemplate getTemplate(RepositoryMetadata metadata) {
|
||||
|
||||
GemfirePersistentEntity<?> entity = mappingContext.getPersistentEntity(metadata.getDomainType())
|
||||
.orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]",
|
||||
metadata.getDomainType()));
|
||||
GemfirePersistentEntity<?> entity = mappingContext.getPersistentEntity(metadata.getDomainType());
|
||||
|
||||
String entityRegionName = entity.getRegionName();
|
||||
String repositoryRegionName = getRepositoryRegionName(metadata.getRepositoryInterface());
|
||||
|
||||
Reference in New Issue
Block a user