net.java.ao.schema.info.CachingEntityInfoResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activeobjects-core Show documentation
Show all versions of activeobjects-core Show documentation
This is the core library for Active Objects. It is generic and can be embedded in any environment.
As such it is generic and won't contain all connection pooling, etc.
package net.java.ao.schema.info;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.java.ao.RawEntity;
/**
* A {@code EntityInfoResolver} which caches the computed {@link EntityInfo} for any type it is given
*/
public class CachingEntityInfoResolver extends EntityInfoResolverWrapper implements EntityInfoResolver {
private final LoadingCache>, EntityInfo> cache;
public CachingEntityInfoResolver(EntityInfoResolver delegate) {
super(delegate);
cache = CacheBuilder.newBuilder().build(new CacheLoader>, EntityInfo>() {
@SuppressWarnings("unchecked")
@Override
public EntityInfo load(Class type) throws Exception {
return CachingEntityInfoResolver.super.resolve(type);
}
});
}
@SuppressWarnings("unchecked")
@Override
public , K> EntityInfo resolve(Class type) {
return cache.getUnchecked(type);
}
}