當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。