Conversation
|
For making reviewers easier, here are the key points. New StorageBuilder/**
* Converter between the give T and K.
*
* @param <T> A storage entity implementation.
*/
public interface StorageBuilder<T extends StorageData> {
/**
* Use the given converter to build an OAP entity object.
*
* @param converter to transfer data format
* @return an OAP entity object
*/
T storage2Entity(Convert2Entity converter);
/**
* Use the given converter to build a database preferred structure.
*
* @param entity to be used
* @param converter provides the converting logic and hosts the converted value. Use {@link
* Convert2Storage#obtain()} to read the converted data.
*/
void entity2Storage(T entity, Convert2Storage converter);
}StorageBuilder wouldn't accept HashMap as a parameter or the return value, now Default HashMapConverterTo keep all codes are changed smoothly, I introduced public class HashMapConverter {
/**
* Stateful Hashmap based converter, build object from a HashMap type source.
*/
@RequiredArgsConstructor
public static class ToEntity implements Convert2Entity {
private final Map<String, Object> source;
@Override
public Object get(final String fieldName) {
return source.get(fieldName);
}
}
/**
* Stateful Hashmap based converter, from object to HashMap.
*/
public static class ToStorage implements Convert2Storage<Map<String, Object>> {
private Map<String, Object> source;
public ToStorage() {
source = new HashMap();
}
@Override
public void accept(final String fieldName, final Object fieldValue) {
source.put(fieldName, fieldValue);
}
@Override
public Object get(final String fieldName) {
return source.get(fieldName);
}
@Override
public Map<String, Object> obtain() {
return source;
}
}
}This HashMapConverter is super easy, just as a wrapper of HashMap. All other code changes are just following these two proposals, and making codes work as usual. Notice, there could be more potential changes for JDBC and other storage plugins, such as wrap ResultSet as a new ToEntity, rather than |
|
We're planning to migrate to this new API, my only concern is that the conversion between binary data and its base64 representation still exists in various entities. So for BanyanDB (we directly store byte array), we still cannot fully take advantage of this refactor. Is that possible we move this conversion somewhere else? Or any sugguestion? |
…8685) * Remove the hard requirement of BASE64 encoding for the binary field, and resolved concerns from #8684 (comment)
CHANGESlog.