package Mybatis;
//
//Source code recreated from a .class file by IntelliJ IDEA
//(powered by Fernflower decompiler)
//
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.ibatis.mapping.ParameterMode;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeAliasRegistry;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;
public abstract class BaseBuilder {
protected final Configuration configuration;
protected final TypeAliasRegistry typeAliasRegistry;
protected final TypeHandlerRegistry typeHandlerRegistry;
public BaseBuilder(Configuration configuration) {
this.configuration = configuration;
this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
this.typeHandlerRegistry = this.configuration.getTypeHandlerRegistry();
}
public Configuration getConfiguration() {
return this.configuration;
}
protected Pattern parseExpression(String regex, String defaultValue) {
return Pattern.compile(regex == null ? defaultValue : regex);
}
protected Boolean booleanValueOf(String value, Boolean defaultValue) {
return value == null ? defaultValue : Boolean.valueOf(value);
}
protected Integer integerValueOf(String value, Integer defaultValue) {
return value == null ? defaultValue : Integer.valueOf(value);
}
protected Set<String> stringSetValueOf(String value, String defaultValue) {
value = value == null ? defaultValue : value;
return new HashSet(Arrays.asList(value.split(",")));
}
protected JdbcType resolveJdbcType(String alias) {
if (alias == null) {
return null;
} else {
try {
return JdbcType.valueOf(alias);
} catch (IllegalArgumentException var3) {
throw new BuilderException("Error resolving JdbcType. Cause: " + var3, var3);
}
}
}
protected ResultSetType resolveResultSetType(String alias) {
if (alias == null) {
return null;
} else {
try {
return ResultSetType.valueOf(alias);
} catch (IllegalArgumentException var3) {
throw new BuilderException("Error resolving ResultSetType. Cause: " + var3, var3);
}
}
}
protected ParameterMode resolveParameterMode(String alias) {
if (alias == null) {
return null;
} else {
try {
return ParameterMode.valueOf(alias);
} catch (IllegalArgumentException var3) {
throw new BuilderException("Error resolving ParameterMode. Cause: " + var3, var3);
}
}
}
protected Object createInstance(String alias) {
Class<?> clazz = this.resolveClass(alias);
if (clazz == null) {
return null;
} else {
try {
return this.resolveClass(alias).newInstance();
} catch (Exception var4) {
throw new BuilderException("Error creating instance. Cause: " + var4, var4);
}
}
}
protected Class<?> resolveClass(String alias) {
if (alias == null) {
return null;
} else {
try {
return this.resolveAlias(alias);
} catch (Exception var3) {
throw new BuilderException("Error resolving class. Cause: " + var3, var3);
}
}
}
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, String typeHandlerAlias) {
if (typeHandlerAlias == null) {
return null;
} else {
Class<?> type = this.resolveClass(typeHandlerAlias);
if (type != null && !TypeHandler.class.isAssignableFrom(type)) {
throw new BuilderException("Type " + type.getName() + " is not a valid TypeHandler because it does not implement TypeHandler interface");
} else {
return this.resolveTypeHandler(javaType, type);
}
}
}
protected TypeHandler<?> resolveTypeHandler(Class<?> javaType, Class<? extends TypeHandler<?>> typeHandlerType) {
if (typeHandlerType == null) {
return null;
} else {
TypeHandler<?> handler = this.typeHandlerRegistry.getMappingTypeHandler(typeHandlerType);
if (handler == null) {
handler = this.typeHandlerRegistry.getInstance(javaType, typeHandlerType);
}
return handler;
}
}
protected Class<?> resolveAlias(String alias) {
return this.typeAliasRegistry.resolveAlias(alias);
}
}
网友评论