use of org.infinispan.commons.dataconversion.Wrapper in project infinispan by infinispan.
the class DataConversion method extractIndexable.
/**
* Convert the stored object in a format suitable to be indexed.
*/
public Object extractIndexable(Object stored) {
if (stored == null)
return null;
// Keys are indexed as stored, without the wrapper
Wrapper wrapper = getWrapper();
if (isKey)
return wrapper.unwrap(stored);
if (wrapper.isFilterable()) {
// If the value wrapper is indexable, return the already wrapped value or wrap it otherwise
return stored.getClass().equals(wrapperClass) ? stored : wrapper.wrap(stored);
}
// Otherwise convert to the request format
Object unencoded = encoder.fromStorage(wrapper.unwrap(stored));
return transcoder == null ? unencoded : transcoder.transcode(unencoded, storageMediaType, requestMediaType);
}
use of org.infinispan.commons.dataconversion.Wrapper in project infinispan by infinispan.
the class CacheNotifierImpl method convertKey.
private K convertKey(CacheEntryListenerInvocation listenerInvocation, K key) {
if (key == null)
return null;
DataConversion keyDataConversion = listenerInvocation.getKeyDataConversion();
Wrapper wrp = keyDataConversion.getWrapper();
Object unwrappedKey = keyDataConversion.getEncoder().fromStorage(wrp.unwrap(key));
CacheEventFilter filter = listenerInvocation.getFilter();
CacheEventConverter converter = listenerInvocation.getConverter();
if (filter == null && converter == null) {
if (listenerInvocation.useStorageFormat()) {
return (K) unwrappedKey;
}
// If no filter is present, convert to the requested format directly
return (K) keyDataConversion.fromStorage(key);
}
MediaType convertFormat = filter == null ? converter.format() : filter.format();
if (listenerInvocation.useStorageFormat() || convertFormat == null) {
// Filter will be run on the storage format, return the unwrapped key
return (K) unwrappedKey;
}
// Filter has a specific format to run, convert to that format
return (K) encoderRegistry.convert(unwrappedKey, keyDataConversion.getStorageMediaType(), convertFormat);
}
use of org.infinispan.commons.dataconversion.Wrapper in project infinispan by infinispan.
the class CacheNotifierImpl method convertValue.
private V convertValue(CacheEntryListenerInvocation listenerInvocation, V value) {
if (value == null)
return null;
DataConversion valueDataConversion = listenerInvocation.getValueDataConversion();
Wrapper wrp = valueDataConversion.getWrapper();
Object unwrappedValue = valueDataConversion.getEncoder().fromStorage(wrp.unwrap(value));
CacheEventFilter filter = listenerInvocation.getFilter();
CacheEventConverter converter = listenerInvocation.getConverter();
if (filter == null && converter == null) {
if (listenerInvocation.useStorageFormat()) {
return (V) unwrappedValue;
}
// If no filter is present, convert to the requested format directly
return (V) valueDataConversion.fromStorage(value);
}
MediaType convertFormat = filter == null ? converter.format() : filter.format();
if (listenerInvocation.useStorageFormat() || convertFormat == null) {
// Filter will be run on the storage format, return the unwrapped key
return (V) unwrappedValue;
}
// Filter has a specific format to run, convert to that format
return (V) encoderRegistry.convert(unwrappedValue, valueDataConversion.getStorageMediaType(), convertFormat);
}
Aggregations