DATAKV-159 - Open up API for extension.
Alter generic type declarations to open up repository related API for better extensibility.
This commit is contained in:
@@ -52,7 +52,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
private static final PersistenceExceptionTranslator DEFAULT_PERSISTENCE_EXCEPTION_TRANSLATOR = new KeyValuePersistenceExceptionTranslator();
|
||||
|
||||
private final KeyValueAdapter adapter;
|
||||
private final MappingContext<? extends KeyValuePersistentEntity<?>, ? extends KeyValuePersistentProperty> mappingContext;
|
||||
private final MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext;
|
||||
private final IdentifierGenerator identifierGenerator;
|
||||
|
||||
private PersistenceExceptionTranslator exceptionTranslator = DEFAULT_PERSISTENCE_EXCEPTION_TRANSLATOR;
|
||||
@@ -78,7 +78,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
*/
|
||||
public KeyValueTemplate(KeyValueAdapter adapter,
|
||||
MappingContext<? extends KeyValuePersistentEntity<?>, ? extends KeyValuePersistentProperty> mappingContext) {
|
||||
MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext) {
|
||||
|
||||
Assert.notNull(adapter, "Adapter must not be null!");
|
||||
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||
@@ -131,7 +131,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
@Override
|
||||
public <T> T insert(T objectToInsert) {
|
||||
|
||||
KeyValuePersistentEntity<?> entity = getKeyValuePersistentEntity(objectToInsert);
|
||||
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToInsert);
|
||||
|
||||
GeneratingIdAccessor generatingIdAccessor = new GeneratingIdAccessor(entity.getPropertyAccessor(objectToInsert),
|
||||
entity.getIdProperty()
|
||||
@@ -143,7 +143,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
return objectToInsert;
|
||||
}
|
||||
|
||||
private KeyValuePersistentEntity<?> getKeyValuePersistentEntity(Object objectToInsert) {
|
||||
private KeyValuePersistentEntity<?, ?> getKeyValuePersistentEntity(Object objectToInsert) {
|
||||
|
||||
return this.mappingContext.getPersistentEntity(ClassUtils.getUserClass(objectToInsert))
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
@@ -190,7 +190,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
@Override
|
||||
public void update(Object objectToUpdate) {
|
||||
|
||||
KeyValuePersistentEntity<?> entity = getKeyValuePersistentEntity(objectToUpdate);
|
||||
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToUpdate);
|
||||
|
||||
if (!entity.hasIdProperty()) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
@@ -329,7 +329,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
public <T> T delete(T objectToDelete) {
|
||||
|
||||
Class<T> type = (Class<T>) ClassUtils.getUserClass(objectToDelete);
|
||||
KeyValuePersistentEntity<?> entity = getKeyValuePersistentEntity(objectToDelete);
|
||||
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToDelete);
|
||||
|
||||
return delete((Serializable) entity.getIdentifierAccessor(objectToDelete).getIdentifier()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Unable to extract 'id' for object to be deleted")), type);
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oliver Gierke
|
||||
* @param <T>
|
||||
*/
|
||||
public class BasicKeyValuePersistentEntity<T> extends BasicPersistentEntity<T, KeyValuePersistentProperty> implements
|
||||
KeyValuePersistentEntity<T> {
|
||||
public class BasicKeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
|
||||
extends BasicPersistentEntity<T, P> implements KeyValuePersistentEntity<T, P> {
|
||||
|
||||
private static final KeySpaceResolver DEFAULT_FALLBACK_RESOLVER = ClassNameKeySpaceResolver.INSTANCE;
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ import org.springframework.data.mapping.model.MutablePersistentEntity;
|
||||
* @author Christoph Strobl
|
||||
* @param <T>
|
||||
*/
|
||||
public interface KeyValuePersistentEntity<T> extends MutablePersistentEntity<T, KeyValuePersistentProperty> {
|
||||
public interface KeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
|
||||
extends MutablePersistentEntity<T, P> {
|
||||
|
||||
/**
|
||||
* Get the {@literal keySpace} a given entity assigns to.
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core.mapping;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -30,9 +27,10 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class KeyValuePersistentProperty extends AnnotationBasedPersistentProperty<KeyValuePersistentProperty> {
|
||||
public class KeyValuePersistentProperty<P extends KeyValuePersistentProperty<P>>
|
||||
extends AnnotationBasedPersistentProperty<P> {
|
||||
|
||||
public KeyValuePersistentProperty(Property property, PersistentEntity<?, KeyValuePersistentProperty> owner,
|
||||
public KeyValuePersistentProperty(Property property, PersistentEntity<?, P> owner,
|
||||
SimpleTypeHolder simpleTypeHolder) {
|
||||
super(property, owner, simpleTypeHolder);
|
||||
}
|
||||
@@ -42,7 +40,7 @@ public class KeyValuePersistentProperty extends AnnotationBasedPersistentPropert
|
||||
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
|
||||
*/
|
||||
@Override
|
||||
protected Association<KeyValuePersistentProperty> createAssociation() {
|
||||
return new Association<KeyValuePersistentProperty>(this, null);
|
||||
protected Association<P> createAssociation() {
|
||||
return new Association<P>((P) this, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core.mapping.context;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.data.keyvalue.core.mapping.BasicKeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
@@ -35,8 +32,8 @@ import org.springframework.data.util.TypeInformation;
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class KeyValueMappingContext extends
|
||||
AbstractMappingContext<KeyValuePersistentEntity<?>, KeyValuePersistentProperty> {
|
||||
public class KeyValueMappingContext<E extends KeyValuePersistentEntity<?, P>, P extends KeyValuePersistentProperty<P>>
|
||||
extends AbstractMappingContext<E, P> {
|
||||
|
||||
private KeySpaceResolver fallbackKeySpaceResolver;
|
||||
|
||||
@@ -49,17 +46,13 @@ public class KeyValueMappingContext extends
|
||||
this.fallbackKeySpaceResolver = fallbackKeySpaceResolver;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation)
|
||||
*/
|
||||
@Override
|
||||
protected <T> KeyValuePersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
return new BasicKeyValuePersistentEntity<T>(typeInformation, fallbackKeySpaceResolver);
|
||||
protected <T> E createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
return (E) new BasicKeyValuePersistentEntity<T, P>(typeInformation, fallbackKeySpaceResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected KeyValuePersistentProperty createPersistentProperty(Property property, KeyValuePersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
return new KeyValuePersistentProperty(property, owner, simpleTypeHolder);
|
||||
protected P createPersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
return (P) new KeyValuePersistentProperty(property, owner, simpleTypeHolder);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user