/**
構造器,根據配置或者代碼生成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);}