net.java.ao.schema.CachingTableNameConverter Maven / Gradle / Ivy
package net.java.ao.schema;
import com.google.common.base.Function;
import com.google.common.collect.MapMaker;
import net.java.ao.RawEntity;
import java.util.Map;
import static com.google.common.base.Preconditions.*;
/**
* A table name converter that simply caches the converted table names.
* This implementation uses a {@link java.util.concurrent.ConcurrentMap} and is thread safe.
*
* @since 0.9
*/
public final class CachingTableNameConverter implements TableNameConverter
{
private final Map>, String> cache;
public CachingTableNameConverter(final TableNameConverter delegateTableNameConverter)
{
checkNotNull(delegateTableNameConverter);
this.cache = new MapMaker().makeComputingMap(new Function>, String>()
{
public String apply(Class extends RawEntity>> entityClass)
{
return delegateTableNameConverter.getName(entityClass);
}
});
}
public String getName(Class extends RawEntity>> entityClass)
{
return cache.get(entityClass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy