本文整理匯總了Java中org.apache.ibatis.session.SqlSessionFactoryBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java SqlSessionFactoryBuilder類的具體用法?Java SqlSessionFactoryBuilder怎麽用?Java SqlSessionFactoryBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SqlSessionFactoryBuilder類屬於org.apache.ibatis.session包,在下文中一共展示了SqlSessionFactoryBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
//mybatis的配置文件
String resource = "mybatis-conf.xml";
//使用類加載器加載mybatis的配置文件(它也加載關聯的映射文件)
InputStream is = Desensitization.class.getClassLoader().getResourceAsStream(resource);
//構建sqlSession的工廠
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
//使用MyBatis提供的Resources類加載mybatis的配置文件(它也加載關聯的映射文件)
//Reader reader = Resources.getResourceAsReader(resource);
//構建sqlSession的工廠
//SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
//創建能執行映射文件中sql的sqlSession
SqlSession session = sessionFactory.openSession();
/**
* 映射sql的標識字符串,
* me.gacl.mapping.userMapper是userMapper.xml文件中mapper標簽的namespace屬性的值,
* getUser是select標簽的id屬性值,通過select標簽的id屬性值就可以找到要執行的SQL
*/
String statement = "com.creditease.dbus.ws.mapper.DesensitizationMapper.getDesensitizationInformation";//映射sql的標識字符串
//執行查詢返回一個唯一user對象的sql
List<DesensitizationInformation> informations = session.selectList(statement,26);
for (DesensitizationInformation information: informations
) {
System.out.println(information);
}
}
示例2: BaseDao
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
BaseDao() {
//判斷SessionFactory是否初始化過,初始化過後就不重複初始化,保證係統的運行效率。
if (!isInit) {
try {
//讀入Mybatis配置文件
inputStream = Resources.getResourceAsStream(resource);
//通過配置文件構建sql數據工廠
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
System.out.println("getConnectionSuccful");
isInit = true;
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("already init");
}
}
示例3: createSqlSessionManager
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
/**
* This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers
*
* @return a {@link SqlSessionFactory}
*/
private SqlSessionManager createSqlSessionManager() {
Environment environment = new Environment(DEFAULT, this.transactionFactory,
taskanaEngineConfiguration.getDatasource());
Configuration configuration = new Configuration(environment);
// add mappers
configuration.addMapper(TaskMapper.class);
configuration.addMapper(TaskMonitorMapper.class);
configuration.addMapper(WorkbasketMapper.class);
configuration.addMapper(DistributionTargetMapper.class);
configuration.addMapper(ClassificationMapper.class);
configuration.addMapper(WorkbasketAccessMapper.class);
configuration.addMapper(ObjectReferenceMapper.class);
configuration.addMapper(QueryMapper.class);
configuration.addMapper(AttachmentMapper.class);
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
return sessionManager;
}
示例4: getSqlSession
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
/**
* 獲取SqlSession
* @return
* @throws IOException
*/
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
config.setCallSettersOnNulls(true); // 設計null調用setter方法
config.setMapUnderscoreToCamelCase(true); // 駝峰命名支持
// 設置mapper
config.addMappers(targetPackage);
// 設置數據源,事務
PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
dataSourceFactory.setProperties(DBHelper.properties);
DataSource dataSource = dataSourceFactory.getDataSource();
JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("test", transactionFactory, dataSource);
config.setEnvironment(environment);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
return sqlSessionFactory.openSession(true);
}
示例5: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Starting up CmsCmProcessor tests");
String resource = "mybatis-config.xml";
Reader reader = Resources.getResourceAsReader( resource );
SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(reader);
session = sf.openSession();
clazzMapper = session.getMapper(ClazzMapper.class);
ciMapper = session.getMapper(CIMapper.class);
mdValidator = new CmsMdValidator();
cmValidator = new CmsCmValidator();
mdProcessor = new CmsMdProcessor();
mdProcessor.setClazzMapper( clazzMapper );
mdProcessor.setMdValidator(mdValidator);
cmProcessor = new CmsCmProcessor();
cmProcessor.setCiMapper(ciMapper);
cmProcessor.setMdProcessor(mdProcessor);
cmProcessor.setCmValidator(cmValidator);
RelationMapper relationMapper=session.getMapper(RelationMapper.class);
mdProcessor.setRelationMapper(relationMapper);
}
示例6: DBManager
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
public DBManager(AppConfiguration appConfig) {
this.appConfig = appConfig;
boolean isDev = appConfig.getBool(CONFIG_KEY_APP_DEV_MODE, true);
String dbHost = appConfig.get(CONFIG_KEY_MYSQL_HOST, DEFAULT_MYSQL_HOST);
int dbPort = appConfig.getInt(CONFIG_KEY_MYSQL_PORT, DEFAULT_MYSQL_PORT);
String dbName = appConfig.get(CONFIG_KEY_MYSQL_DBNAME, DEFAULT_MEYSQL_DBNAME);
String dbUser = appConfig.get(CONFIG_KEY_MYSQL_USER, "");
String dbPass = appConfig.get(CONFIG_KEY_MYSQL_PASS, "");
String dbDriver = "com.mysql.cj.jdbc.Driver";
String connString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "?autoReconnect=true&useSSL=false&useUnicode=true";
DataSource dataSource = new PooledDataSource(dbDriver, connString, dbUser, dbPass);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment(isDev ? "development" : "production", transactionFactory, dataSource);
configuration = new Configuration(environment);
configuration.addMappers("com.elune.dao");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
示例7: build
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
/**
* Create an instance of MyBatis.
*
* @param environment The dropwizard environment
* @param config A Mybatis config object
* @param dataSource
* @param name The name of this mybatis factory used for metrics
* @return An instance of MyBatis.
*/
public final SqlSessionFactory build(Environment environment,
MyBatisConfiguration config,
ManagedDataSource dataSource,
String name) {
SqlSessionFactory sessionFactory = null;
// Try to use the mybatis configuration file if it is specified and exists.
try (InputStream inputStream = Resources.getResourceAsStream(config.getConfigFile())) {
sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException ioe) {
// Build session factory from configuration values given in the dropwizard config.
TransactionFactory transactionFactory = new JdbcTransactionFactory();
org.apache.ibatis.mapping.Environment myBatisEnvironment =
new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
}
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name,
new MyBatisHealthCheck(sessionFactory, config.getConfig().getValidationQuery()));
return sessionFactory;
}
示例8: init
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@Override
public void init(DbConnection connection) throws Exception {
JdbcConnectionPool pool = JdbcConnectionPool.create(connection.uri, connection.username, connection.password);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("jdblender", transactionFactory, pool);
Configuration cfg = new Configuration(environment);
cfg.setMapUnderscoreToCamelCase(true);
cfg.addMapper(BrandsMapper.class);
cfg.addMapper(SeriesMapper.class);
cfg.addMapper(ModelsMapper.class);
cfg.addMapper(SparesMapper.class);
//Create session
sqlSessionFactory = new SqlSessionFactoryBuilder().build(cfg);
}
示例9: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例10: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/include_property/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/include_property/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例11: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtest/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtest/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例12: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例13: before
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@Before
public void before() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/mybatis-config-" + getConfiguration() + ".xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
sqlSession = sqlSessionFactory.openSession();
mapper = sqlSession.getMapper(Mapper.class);
}
示例14: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例15: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources
.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources
.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}