DATAKV-117 - Pass on type information to KV Adapter.
Original pull request: #18.
This commit is contained in:
committed by
Mark Paluch
parent
551b27deb2
commit
fae6d418b6
@@ -57,6 +57,33 @@ public abstract class AbstractKeyValueAdapter implements KeyValueAdapter {
|
||||
return engine;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T get(Serializable id, Serializable keyspace, Class<T> type) {
|
||||
return (T) get(id, keyspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> T delete(Serializable id, Serializable keyspace, Class<T> type) {
|
||||
return (T) delete(id, keyspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public <T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
|
||||
return (Iterable<T>) engine.execute(query, keyspace, type);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
|
||||
|
||||
@@ -58,6 +58,15 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
*/
|
||||
Object get(Serializable id, Serializable keyspace);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param keyspace
|
||||
* @param type
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> T get(Serializable id, Serializable keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Delete and return the obect with given type and id.
|
||||
*
|
||||
@@ -67,6 +76,15 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
*/
|
||||
Object delete(Serializable id, Serializable keyspace);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param keyspace
|
||||
* @param type
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> T delete(Serializable id, Serializable keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get all elements for given keyspace.
|
||||
*
|
||||
@@ -104,6 +122,15 @@ public interface KeyValueAdapter extends DisposableBean {
|
||||
*/
|
||||
Iterable<?> find(KeyValueQuery<?> query, Serializable keyspace);
|
||||
|
||||
/**
|
||||
* @param query
|
||||
* @param keyspace
|
||||
* @param type
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
<T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type);
|
||||
|
||||
/**
|
||||
* Count number of objects within {@literal keyspace}.
|
||||
*
|
||||
|
||||
@@ -271,7 +271,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
@Override
|
||||
public T doInKeyValue(KeyValueAdapter adapter) {
|
||||
|
||||
Object result = adapter.get(id, keyspace);
|
||||
Object result = adapter.get(id, keyspace, type);
|
||||
|
||||
if (result == null || typeCheck(type, result)) {
|
||||
return (T) result;
|
||||
@@ -342,10 +342,9 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
|
||||
T result = execute(new KeyValueCallback<T>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T doInKeyValue(KeyValueAdapter adapter) {
|
||||
return (T) adapter.delete(id, keyspace);
|
||||
return (T) adapter.delete(id, keyspace, type);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -394,7 +393,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationEventPub
|
||||
@Override
|
||||
public Iterable<T> doInKeyValue(KeyValueAdapter adapter) {
|
||||
|
||||
Iterable<?> result = adapter.find(query, resolveKeySpace(type));
|
||||
Iterable<?> result = adapter.find(query, resolveKeySpace(type), type);
|
||||
if (result == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,21 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
return execute(criteria, sort, query.getOffset(), query.getRows(), keyspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract query attributes and delegate to concrete execution.
|
||||
*
|
||||
* @param query
|
||||
* @param keyspace
|
||||
* @return
|
||||
*/
|
||||
public <T> Collection<T> execute(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
|
||||
|
||||
CRITERIA criteria = this.criteriaAccessor != null ? this.criteriaAccessor.resolve(query) : null;
|
||||
SORT sort = this.sortAccessor != null ? this.sortAccessor.resolve(query) : null;
|
||||
|
||||
return execute(criteria, sort, query.getOffset(), query.getRows(), keyspace, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract query attributes and delegate to concrete execution.
|
||||
*
|
||||
@@ -79,6 +94,21 @@ public abstract class QueryEngine<ADAPTER extends KeyValueAdapter, CRITERIA, SOR
|
||||
*/
|
||||
public abstract Collection<?> execute(CRITERIA criteria, SORT sort, int offset, int rows, Serializable keyspace);
|
||||
|
||||
/**
|
||||
* @param criteria
|
||||
* @param sort
|
||||
* @param offset
|
||||
* @param rows
|
||||
* @param keyspace
|
||||
* @param type
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
public <T> Collection<T> execute(CRITERIA criteria, SORT sort, int offset, int rows, Serializable keyspace,
|
||||
Class<T> type) {
|
||||
return (Collection<T>) execute(criteria, sort, offset, rows, keyspace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param criteria
|
||||
* @param keyspace
|
||||
|
||||
Reference in New Issue
Block a user