org.babyfish.jimmer.sql.cache.CacheLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
package org.babyfish.jimmer.sql.cache;
import org.babyfish.jimmer.impl.util.ClassCache;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.meta.TargetLevel;
import org.babyfish.jimmer.sql.JSqlClient;
import org.babyfish.jimmer.sql.fetcher.Fetcher;
import org.babyfish.jimmer.sql.fetcher.IdOnlyFetchType;
import org.babyfish.jimmer.sql.fetcher.impl.FetcherImpl;
import java.sql.Connection;
import java.util.Collection;
import java.util.Map;
@FunctionalInterface
public interface CacheLoader {
Map loadAll(Collection keys);
static CacheLoader objectLoader(
JSqlClient sqlClient,
Connection con,
Class entityType
) {
return keys -> sqlClient
.getEntities()
.forConnection(con)
.findMapByIds(ObjectCacheFetchers.of(entityType), keys);
}
}
class ObjectCacheFetchers {
private static final ClassCache> CACHE = new ClassCache<>(
ObjectCacheFetchers::create,
false
);
@SuppressWarnings("unchecked")
static Fetcher of(Class type) {
return (Fetcher) CACHE.get(type);
}
@SuppressWarnings("unchecked")
private static Fetcher> create(Class> type) {
ImmutableType immutableType = ImmutableType.get(type);
Fetcher> fetcher = new FetcherImpl<>((Class