Search in sources :

Example 1 with Wrapper

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);
}
Also used : Wrapper(org.infinispan.commons.dataconversion.Wrapper) ByteArrayWrapper(org.infinispan.commons.dataconversion.ByteArrayWrapper) IdentityWrapper(org.infinispan.commons.dataconversion.IdentityWrapper)

Example 2 with Wrapper

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);
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) Wrapper(org.infinispan.commons.dataconversion.Wrapper) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 3 with Wrapper

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);
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) Wrapper(org.infinispan.commons.dataconversion.Wrapper) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) MediaType(org.infinispan.commons.dataconversion.MediaType)

Aggregations

Wrapper (org.infinispan.commons.dataconversion.Wrapper)3 MediaType (org.infinispan.commons.dataconversion.MediaType)2 DataConversion (org.infinispan.encoding.DataConversion)2 CacheEventConverter (org.infinispan.notifications.cachelistener.filter.CacheEventConverter)2 CacheEventFilter (org.infinispan.notifications.cachelistener.filter.CacheEventFilter)2 ByteArrayWrapper (org.infinispan.commons.dataconversion.ByteArrayWrapper)1 IdentityWrapper (org.infinispan.commons.dataconversion.IdentityWrapper)1