/**
构造器,根据配置或者代码生成SqlSessionFactory,采用分布构建的Builder模式
/*
public class SqlSessionFactoryBuilder {
/**
传入用于读取字符流的类。
/*
public SqlSessionFactory build(Reader reader) {
return build(reader, null, null);
}
/**
传入用于读取字符流的类和环境配置(不同环境数据库各种连接配置不一样)
/*
public SqlSessionFactory build(Reader reader, String environment) {
return build(reader, environment, null);
}
/**
传入用于读取字符流的类和环境配置(不同环境数据库各种连接配置不一样)
/*
public SqlSessionFactory build(Reader reader, Properties properties)
{ return build(reader, null, properties);
}
/**
传入用于读取字符流的类和配置文件
/*
public SqlSessionFactory build(Reader reader, Properties properties) {
return build(reader, null, properties);
}
/* 构造
SqlSessionFactory 具体实现(传入字符流)
/*
public SqlSessionFactory build(Reader reader, String environment, Properties properties) {
try {
XMLConfigBuilder parser = new XMLConfigBuilder(reader, environment, properties);
return build(parser.parse());
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error building SqlSession.", e);
} finally {
ErrorContext.instance().reset();
try {
reader.close();
} catch (IOException e) {
// Intentionally ignore. Prefer previous error.
}
}
}
/**
传入字节流
/*
public SqlSessionFactory build(InputStream inputStream) {
return build(inputStream, null, null);
}
/**
传入字节流和环境配置
/*
public SqlSessionFactory build(InputStream inputStream, String environment) {
return build(inputStream, environment, null);
}
/**
传入字节流和配置文件
/*
public SqlSessionFactory build(InputStream inputStream, Properties properties) {
return build(inputStream, null, properties);
}
/* 构造
SqlSessionFactory 具体实现(传入字节流)
/*
public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
try {
XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);
return build(parser.parse());
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error building SqlSession.", e);
} finally {
ErrorContext.instance().reset();
try {
inputStream.close();
} catch (IOException e) {
// Intentionally ignore. Prefer previous error.
}
}
}
/**
核心,根据配置配置生成SqlSessionFactory 以上实现都是读取配置转换成配置对象在调用此方法。
/*
public SqlSessionFactory build(Configuration config) {
return new DefaultSqlSessionFactory(config);
}