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

net.java.ao.schema.CachingTableNameConverter Maven / Gradle / Ivy

Go to download

This is the full Active Objects library, if you don't know which one to use, you probably want this one.

The newest version!
package net.java.ao.schema;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.java.ao.RawEntity;

import java.util.Objects;


/**
 * 

A table name converter that simply caches the converted table names.

*

This implementation uses a {@link com.google.common.cache.LoadingCache} and is thread safe.

* * @since 0.9 */ public class CachingTableNameConverter implements TableNameConverter { private final LoadingCache>, String> cache; public CachingTableNameConverter(final TableNameConverter delegateTableNameConverter) { Objects.requireNonNull(delegateTableNameConverter, "delegateTableNameConverter can't be null"); this.cache = CacheBuilder.newBuilder().build(new CacheLoader>, String>() { @Override public String load(final Class> key) throws Exception { return delegateTableNameConverter.getName(key); } }); } public String getName(Class> entityClass) { return cache.getUnchecked(entityClass); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy