io.github.nichetoolkit.mybatis.defaults.DefaultCachingTableFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-toolkit-context Show documentation
Show all versions of mybatis-toolkit-context Show documentation
Mybatis toolkit context project for Spring Boot
The newest version!
package io.github.nichetoolkit.mybatis.defaults;
import io.github.nichetoolkit.mybatis.MybatisTable;
import io.github.nichetoolkit.mybatis.MybatisTableFactory;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* DefaultCachingTableFactory
* The default caching table factory class.
* @author Cyan ([email protected])
* @see io.github.nichetoolkit.mybatis.MybatisTableFactory
* @since Jdk1.8
*/
public class DefaultCachingTableFactory implements MybatisTableFactory {
/**
* classTables
* {@link java.util.Map} The classTables
field.
* @see java.util.Map
*/
private final Map, MybatisTable> classTables;
/**
* DefaultCachingTableFactory
* Instantiates a new default caching table factory.
*/
public DefaultCachingTableFactory() {
this.classTables = new ConcurrentHashMap<>();
}
@Override
public boolean supports(@NonNull Class> entityType) {
return true;
}
@Override
@SuppressWarnings("all")
public MybatisTable createTable(@NonNull Class> entityType, @Nullable Class> identityType, @Nullable Class> linkageType, @Nullable Class> alertnessType, Chain chain) {
if (this.classTables.get(entityType) == null) {
synchronized (entityType) {
if (this.classTables.get(entityType) == null) {
MybatisTable mybatisTable = chain.createTable(entityType, identityType, linkageType, alertnessType);
if (mybatisTable != null) {
this.classTables.put(entityType, mybatisTable);
} else {
return null;
}
}
}
}
return this.classTables.get(entityType);
}
@Override
public int getOrder() {
return Integer.MAX_VALUE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy