本文整理汇总了Java中org.apache.ibatis.session.SqlSession.close方法的典型用法代码示例。如果您正苦于以下问题:Java SqlSession.close方法的具体用法?Java SqlSession.close怎么用?Java SqlSession.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.session.SqlSession
的用法示例。
在下文中一共展示了SqlSession.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateByPrimaryKeySelective
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 根据主键更新非null
*/
@Test
public void testUpdateByPrimaryKeySelective() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
UserInfo userInfo = mapper.selectByPrimaryKey(1);
Assert.assertNotNull(userInfo);
userInfo.setUsertype(null);
userInfo.setEmail("[email protected]");
//不会更新username
Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(userInfo));
userInfo = mapper.selectByPrimaryKey(1);
Assert.assertEquals("1", userInfo.getUsertype());
Assert.assertEquals("[email protected]", userInfo.getEmail());
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例2: deleteUserGroupById
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static boolean deleteUserGroupById(String userGroupId) {
SqlSession sqlSession = null;
try {
sqlSession = MybatisManager.getSqlSession();
UserGroupMapper userGroupMapper = sqlSession.getMapper(UserGroupMapper.class);
int result = userGroupMapper.deleteByPrimaryKey(userGroupId);
if (result == 0) {
MybatisManager.log.warn("删除用户组异常");
return false;
}
sqlSession.commit();
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("删除用户组异常", e);
return false;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
return true;
}
示例3: delete
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
*
* @param expr
* @return
* @throws SQLException
*/
public <T> int delete(T entity,ExprBuilder... exprs) throws Exception{
SqlSession session=getSession();
try {
SqlRunner sqlRunner = new DefaultSqlRunner(session.getConnection());
List<Object> parameter = new LinkedList<Object>();
String tableName=getTableName(entity);
String whereSql=getWhereSql(entity,parameter,exprs);
String sql=StringUtils.appendAll("delete from ",tableName+whereSql);
logger.debug(sql);
int effect=sqlRunner.delete(sql, parameter);
logger.debug("删除了"+effect+"行");
if(effect>0){
clearCache(entity);
}
return effect;
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
throw e;
} finally {
session.close();
}
}
示例4: testDynamicUpdateByPrimaryKeyNotFoundKeyProperties
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 继承类可以使用,但多出来的属性无效
*/
@Test
public void testDynamicUpdateByPrimaryKeyNotFoundKeyProperties() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Assert.assertEquals(0, mapper.updateByPrimaryKey(new Key()));
Key key = new Key();
key.setId(174);
key.setCountrycode("CN");
key.setCountrytel("+86");
Assert.assertEquals(1, mapper.updateByPrimaryKey(key));
} finally {
sqlSession.close();
}
}
示例5: testDeleteByExample3
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void testDeleteByExample3() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
CountryExample example = new CountryExample();
example.createCriteria().andCountrynameLike("A%");
example.or().andIdGreaterThan(100);
example.setDistinct(true);
int count = mapper.deleteByExample(example);
//查询总数
Assert.assertEquals(true, count > 83);
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例6: testDynamicSelectZero
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 查询不存在的结果
*/
@Test
public void testDynamicSelectZero() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Country country = new Country();
country.setCountrycode("CN");
country.setCountryname("天朝");//实际上是 China
Country result = mapper.selectOne(country);
Assert.assertNull(result);
} finally {
sqlSession.close();
}
}
示例7: setUp
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
SqlSession session = sqlSessionTemplate.getSqlSessionFactory().openSession();
Connection conn = session.getConnection();
Reader reader = Resources.getResourceAsReader("com/baomidou/mybatisplus/test/plugins/paginationInterceptor/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
// 随机当前页和分页大小
size = RandomUtils.nextInt(1, 50);
current = RandomUtils.nextInt(1, 200 / size);
System.err.println("当前页为:" + current + " 分页大小为" + size);
}
示例8: selectArticleContent
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public String selectArticleContent(String articleid) throws Exception {
SqlSession os = sqlSessionFactory.openSession();
String articleDetail = os.selectOne("selectArticleContent", articleid);
os.close();
return articleDetail;
}
示例9: getNotify
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Notify getNotify(String notifyId) {
if (StringUtil.stringIsNull(notifyId)) {
return null;
}
SqlSession sqlSession = null;
Notify notify;
try {
sqlSession = MybatisManager.getSqlSession();
NotifyMapper notifyMapper = sqlSession.getMapper(NotifyMapper.class);
notify = notifyMapper.selectByPrimaryKey(notifyId);
if (notify == null) {
MybatisManager.log.warn("通过notifyId:" + notifyId + "获取notify为空");
}
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("获取notify异常", e);
return null;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
return notify;
}
示例10: selectArticleByClassifyid
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public List<Map> selectArticleByClassifyid(Map map) throws Exception {
SqlSession os = sqlSessionFactory.openSession();
List<Map> list = os.selectList("selectArticleByClassifyid", map);
os.close();
return list;
}
示例11: testDynamicInsertAll
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 插入空数据,id不能为null,会报错
*/
@Test(expected = PersistenceException.class)
public void testDynamicInsertAll() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
mapper.insertSelective(new Country());
} finally {
sqlSession.close();
}
}
示例12: main
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 测试 Mybatis XML 修改自动刷新
*/
public static void main(String[] args) throws IOException, InterruptedException {
InputStream in = UserMapperTest.class.getClassLoader().getResourceAsStream("mysql-config.xml");
MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();
mf.setGlobalConfig(new GlobalConfiguration(new MySqlInjector()));
Resource[] resource = new ClassPathResource[]{new ClassPathResource("mysql/UserMapper.xml")};
SqlSessionFactory sessionFactory = mf.build(in);
new MybatisMapperRefresh(resource, sessionFactory, 0, 5);
boolean isReturn = false;
SqlSession session = null;
while (!isReturn) {
try {
session = sessionFactory.openSession();
UserMapper userMapper = session.getMapper(UserMapper.class);
userMapper.selectListRow(new Pagination(1, 10));
resource[0].getFile().setLastModified(SystemClock.now());
session.commit();
session.close();
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.close();
}
Thread.sleep(5000);
}
}
System.exit(0);
}
示例13: selectUserByEmail
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public List<Userinfo> selectUserByEmail(String user_email) throws Exception {
SqlSession os = sqlSessionFactory.openSession();
List<Userinfo> userList = os.selectList("selectUserByEmail",user_email);
os.close();
return userList;
}
示例14: selectCollectNotifyByUserid
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public int selectCollectNotifyByUserid(String userid) throws Exception {
SqlSession os = sqlSessionFactory.openSession();
int i = os.selectOne("selectCollectNotifyByUserid", userid);
os.close();
return i;
}
示例15: updateCard
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public void updateCard(Cardcase cardinfo) {
SqlSession os = sqlSessionFactory.openSession();
os.update("updateCard", cardinfo);
os.close();
}