All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.babyfish.jimmer.sql.cache.spi.AbstractRemoteValueBinder Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.cache.spi;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.sql.cache.CacheTracker;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public abstract class AbstractRemoteValueBinder
        extends AbstractRemoteBinder {

    protected AbstractRemoteValueBinder(
            @Nullable ImmutableType type,
            @Nullable ImmutableProp prop,
            @Nullable CacheTracker tracker,
            @Nullable ObjectMapper objectMapper,
            Duration duration,
            int randomPercent
    ) {
        super(type, prop, tracker, objectMapper, duration, randomPercent);
    }

    @Override
    public final Map getAll(Collection keys) {
        Collection redisKeys = serializedKeys(keys);
        List values = read(redisKeys);
        return valueSerializer.deserialize(keys, values);
    }

    @Override
    public final void setAll(Map map) {
        Map convertedMap = valueSerializer.serialize(map, this::serializedKey);
        write(convertedMap);
    }

    protected abstract List read(Collection keys);

    protected abstract void write(Map map);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy