本文整理汇总了Java中org.apache.ibatis.session.defaults.DefaultSqlSessionFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultSqlSessionFactory类的具体用法?Java DefaultSqlSessionFactory怎么用?Java DefaultSqlSessionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultSqlSessionFactory类属于org.apache.ibatis.session.defaults包,在下文中一共展示了DefaultSqlSessionFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfiguration
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Test
public void testConfiguration() {
UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
Properties dataSourceProperties = new Properties();
dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
dataSourceProperties.put("username", "sa");
dataSourceFactory.setProperties(dataSourceProperties);
Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
Configuration configuration = new Configuration();
configuration.setEnvironment(environment);
configuration.getTypeAliasRegistry().registerAlias(Person.class);
configuration.addMapper(PersonMapper.class);
configuration.addMapper(PersonMapper2.class);
new DefaultSqlSessionFactory(configuration);
}
示例2: getSqlSessionFactoryWithConstructor
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
Properties properties = new Properties();
properties.setProperty("driver", "org.hsqldb.jdbcDriver");
properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
properties.setProperty("username", "sa");
unpooledDataSourceFactory.setProperties(properties);
Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
Configuration configuration = new Configuration();
configuration.setEnvironment(environment);
configuration.addMapper(StudentConstructorMapper.class);
configuration.addMapper(TeacherMapper.class);
configuration.getMappedStatementNames();
configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
return new DefaultSqlSessionFactory(configuration);
}
示例3: getObject
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Override
public SqlSessionFactory getObject() throws Exception {
SqlSessionFactory sqlSessionFactory = super.getObject();
if (sqlSessionFactory instanceof DefaultSqlSessionFactory)
return proxy(sqlSessionFactory, methodInvocation -> {
if (methodInvocation.getMethod().getName().equals("openSession")) {
SqlSession session = (SqlSession) methodInvocation.proceed();
if (session instanceof DefaultSqlSession) {
DefaultSqlSession defaultSqlSession = (DefaultSqlSession) session;
Executor executor = (Executor) ReflectionUtils.getFieldValue(defaultSqlSession, "executor");
if (executor instanceof CachingExecutor) {
CachingExecutor cachingExecutor = (CachingExecutor) executor;
SimpleExecutor ex = (SimpleExecutor) ReflectionUtils.getFieldValue(cachingExecutor, "delegate");
System.out.println("ex-> " + ex.getClass().getName());
ReflectionUtils.setDeclaredFieldValue(cachingExecutor, "delegate", proxy(ex, invocation -> {
System.out.println("method->" + invocation.getMethod());
return invocation.proceed();
}));
}
}
return session;
}
return methodInvocation.proceed();
});
return sqlSessionFactory;
}
示例4: shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Test(expected = BindingException.class)
public void shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers() {
Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
configuration.addMapper(AuthorMapperWithMultipleHandlers.class);
SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession();
try {
DefaultResultHandler handler1 = new DefaultResultHandler();
DefaultResultHandler handler2 = new DefaultResultHandler();
AuthorMapperWithMultipleHandlers mapper = sqlSession.getMapper(AuthorMapperWithMultipleHandlers.class);
mapper.selectAuthor(101, handler1, handler2);
} finally {
sqlSession.close();
}
}
示例5: shouldFailSelectOneAuthorUsingMapperClassWithTwoRowBounds
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Test(expected = BindingException.class)
public void shouldFailSelectOneAuthorUsingMapperClassWithTwoRowBounds() {
Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
configuration.addMapper(AuthorMapperWithRowBounds.class);
SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession();
try {
RowBounds bounds1 = new RowBounds(0, 1);
RowBounds bounds2 = new RowBounds(0, 1);
AuthorMapperWithRowBounds mapper = sqlSession.getMapper(AuthorMapperWithRowBounds.class);
mapper.selectAuthor(101, bounds1, bounds2);
} finally {
sqlSession.close();
}
}
示例6: shouldUseDefaultId
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Test
public void shouldUseDefaultId() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/MultiDbConfig.xml");
DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
Configuration c = sqlSessionFactory.getConfiguration();
assertEquals("hsql", c.getDatabaseId());
}
示例7: shouldUseProvider
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Test
public void shouldUseProvider() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/ProviderConfig.xml");
DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
Configuration c = sqlSessionFactory.getConfiguration();
assertEquals("translated", c.getDatabaseId());
}
示例8: build
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
public SqlSessionFactory build(Configuration config) {
return new DefaultSqlSessionFactory(config);
}
示例9: build
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
public SqlSessionFactory build(Configuration config) {
// 源码解析: 创建SqlSession工厂, 传入Configuration对象
return new DefaultSqlSessionFactory(config);
}
示例10: instantiate
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
@Before
public void instantiate() {
factory = new JxSqlSessionFactory(new DefaultSqlSessionFactory(null));
}
示例11: main
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TestH2 h2 = new TestH2();
// 开始服务
h2.startServer();
h2.testH2();
Class.forName("org.h2.Driver");
JdbcDataSource JdbcDataSource=new JdbcDataSource();
JdbcDataSource.setUrl("jdbc:h2:./test");
JdbcDataSource.setUser("sa");
JdbcDataSource.setPassword("");
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("Production", transactionFactory, JdbcDataSource);
Configuration configuration = new Configuration(environment);
configuration.addMapper(PersonMapper.class);
SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
SqlSession sqlSession = sqlSessionFactory.openSession();
PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
Person person=new Person();
person.setId(1);
Person person1= personMapper.queryByPrimaryKey(person);
System.out.println(person1);
h2.stopServer();
}
示例12: build
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; //导入依赖的package包/类
/**
* MyBatis内部通过Configuration对象来创建SqlSessionFactory,
* 用户也可以自己通过API构造好Configuration对象,调用此方法创建SqlSessionFactory
* @param config
* @return
*/
public SqlSessionFactory build(Configuration config) {
return new DefaultSqlSessionFactory(config);
}