当前位置: 首页>>代码示例>>Java>>正文


Java SqlSession.close方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:24,代码来源:TestBasic.java

示例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;
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:25,代码来源:UserGroupAction.java

示例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();
	}
}
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:29,代码来源:BaseMapperImpl.java

示例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();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:21,代码来源:TestUpdateByPrimaryKey.java

示例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();
    }
}
 
开发者ID:godlike110,项目名称:tk-mybatis,代码行数:18,代码来源:TestDeleteByExample.java

示例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();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:19,代码来源:TestSelectOne.java

示例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);
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:16,代码来源:PaginationInterceptorTest.java

示例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;
}
 
开发者ID:viakiba,项目名称:karanotes,代码行数:8,代码来源:ArticleDaoImpl.java

示例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;

}
 
开发者ID:dianbaer,项目名称:epay,代码行数:28,代码来源:NotifyAction.java

示例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;
}
 
开发者ID:viakiba,项目名称:karanotes,代码行数:8,代码来源:ArticleDaoImpl.java

示例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();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:14,代码来源:TestInsertSelective.java

示例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);
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:33,代码来源:MybatisMapperRefreshTest.java

示例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;
}
 
开发者ID:viakiba,项目名称:karanotes,代码行数:8,代码来源:UserinfoDaoImpl.java

示例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;
}
 
开发者ID:viakiba,项目名称:karanotes,代码行数:8,代码来源:CollectDaoImpl.java

示例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();
}
 
开发者ID:viakiba,项目名称:wxcard,代码行数:7,代码来源:CardcaseDaoImpl.java


注:本文中的org.apache.ibatis.session.SqlSession.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。