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


Java SqlSession.rollback方法代码示例

本文整理汇总了Java中org.apache.ibatis.session.SqlSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Java SqlSession.rollback方法的具体用法?Java SqlSession.rollback怎么用?Java SqlSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.session.SqlSession的用法示例。


在下文中一共展示了SqlSession.rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDeleteByExample2

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void testDeleteByExample2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.createCriteria().andLike("countryname", "A%");
        example.or().andGreaterThan("id", 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

示例2: testInsert

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
 * 新增
 */
@Test
public void testInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoAbleMapper mapper = sqlSession.getMapper(UserInfoAbleMapper.class);
        UserInfoAble userInfo = new UserInfoAble();
        userInfo.setUsername("abel533");
        userInfo.setPassword("123456");
        userInfo.setUsertype("2");
        userInfo.setEmail("[email protected]");//insert=false

        Assert.assertEquals(1, mapper.insert(userInfo));

        Assert.assertNotNull(userInfo.getId());
        Assert.assertEquals(6, (int) userInfo.getId());

        userInfo = mapper.selectByPrimaryKey(userInfo.getId());
        //email没有插入
        Assert.assertNull(userInfo.getEmail());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:28,代码来源:TestBasicAble.java

示例3: getUserGroupById

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static UserGroup getUserGroupById(String userGroupId) {
	if (StringUtil.stringIsNull(userGroupId)) {
		return null;
	}
	SqlSession sqlSession = null;
	UserGroup userGroup;
	try {
		sqlSession = MybatisManager.getSqlSession();
		UserGroupMapper userGroupMapper = sqlSession.getMapper(UserGroupMapper.class);
		userGroup = userGroupMapper.selectByPrimaryKey(userGroupId);
		if (userGroup == null) {
			MybatisManager.log.warn("通过userGroupId:" + userGroupId + "获取用户组为空");
		}
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取用户组异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
	return userGroup;
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:27,代码来源:UserGroupAction.java

示例4: getChatById

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Chat getChatById(String chatId) {
	if (StringUtil.stringIsNull(chatId)) {
		return null;
	}
	SqlSession sqlSession = null;
	Chat chat;
	try {
		sqlSession = MybatisManager.getSqlSession();
		ChatMapper chatMapper = sqlSession.getMapper(ChatMapper.class);
		chat = chatMapper.selectByPrimaryKey(chatId);
		if (chat == null) {
			MybatisManager.log.warn("通过chatId:" + chatId + "获取聊天内容为空");
		}
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取聊天内容异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
	return chat;
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:27,代码来源:ChatAction.java

示例5: getUserList

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static List<User> getUserList(String userGroupId, boolean isRecursion, boolean isUserGroupIsNull, int userState, int userSex, int userRole, String userGroupTopId, String userName, String userCreateTimeGreaterThan, String userCreateTimeLessThan, String userUpdateTimeGreaterThan, String userUpdateTimeLessThan) {
	SqlSession sqlSession = null;
	List<User> userListAll = new ArrayList<>();
	try {
		sqlSession = MybatisManager.getSqlSession();
		UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
		UserGroupMapper userGroupMapper = sqlSession.getMapper(UserGroupMapper.class);
		getUserListRecursion(userListAll, userGroupId, userState, userSex, userRole, userGroupMapper, userMapper, isRecursion, userGroupTopId, isUserGroupIsNull, userName, userCreateTimeGreaterThan, userCreateTimeLessThan, userUpdateTimeGreaterThan, userUpdateTimeLessThan);
		return userListAll;
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取用户列表异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:22,代码来源:UserAction.java

示例6: testUpdateByPrimaryKey

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
 * 根据主键全更新
 */
@Test
public void testUpdateByPrimaryKey() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
        UserInfo userInfo = mapper.selectByPrimaryKey(2);
        Assert.assertNotNull(userInfo);
        userInfo.setUsertype(null);
        userInfo.setEmail("[email protected]");
        //不会更新username
        Assert.assertEquals(1, mapper.updateByPrimaryKey(userInfo));

        userInfo = mapper.selectByPrimaryKey(userInfo);
        Assert.assertNull(userInfo.getUsertype());
        Assert.assertEquals("[email protected]", userInfo.getEmail());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:24,代码来源:TestBasic.java

示例7: getTokenByUserId

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Token getTokenByUserId(String userId) {
	if (StringUtil.stringIsNull(userId)) {
		return null;
	}
	SqlSession sqlSession = null;
	try {
		sqlSession = MybatisManager.getSqlSession();
		TokenMapper tokenMapper = sqlSession.getMapper(TokenMapper.class);
		TokenCriteria tokenCriteria = new TokenCriteria();
		TokenCriteria.Criteria criteria = tokenCriteria.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<Token> tokenList = tokenMapper.selectByExample(tokenCriteria);
		if (tokenList == null || tokenList.size() == 0) {
			return null;
		}
		return tokenList.get(0);
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取token异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:29,代码来源:TokenAction.java

示例8: test

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void test() {
	Testtable testtable = new Testtable();
	testtable.setId(UUID.randomUUID().toString());
	testtable.setName("test");
	testtable.setTime(new Date());
	SqlSession sqlSession = null;
	int result = 0;
	try {
		sqlSession = MybatisManager.getSqlSession();
		TesttableMapper testtableMapper = sqlSession.getMapper(TesttableMapper.class);
		result = testtableMapper.insert(testtable);
		if (result == 0) {
			throw new Exception();
		}
		sqlSession.commit();
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
	assertEquals(1, result);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:28,代码来源:MybatisManagerTest.java

示例9: getUserChatNum

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static long getUserChatNum(String toTypeId, String fromUserId, String chatCreateTime) {
	if (StringUtil.stringIsNull(toTypeId) || StringUtil.stringIsNull(fromUserId)) {
		return 0;
	}
	Date date = null;
	if (!StringUtil.stringIsNull(chatCreateTime)) {
		date = TimeUtils.stringToDateDay(chatCreateTime);
	}
	SqlSession sqlSession = null;
	try {
		sqlSession = MybatisManager.getSqlSession();
		ChatMapperExt chatMapperExt = sqlSession.getMapper(ChatMapperExt.class);
		ChatCriteriaExt chatCriteria = new ChatCriteriaExt();

		chatCriteria.setToType((byte) ChatConfig.TO_TYPE_USER);

		chatCriteria.setToTypeId(toTypeId);
		chatCriteria.setFromUserId(fromUserId);
		if (date != null) {
			chatCriteria.setChatCreateTime(date);
		}
		chatCriteria.setChatState((byte) ChatConfig.CHAT_STATE_EXIST);
		long result = chatMapperExt.countByExample(chatCriteria);
		return result;
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取聊天异常", e);
		return 0;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:37,代码来源:ChatAction.java

示例10: updateNotify

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Notify updateNotify(String notifyId, String notifyResult) {
	if (StringUtil.stringIsNull(notifyId)) {
		return null;
	}
	Notify notify = getNotify(notifyId);
	if (notify == null) {
		return null;
	}
	Notify notifyNew = new Notify();
	notifyNew.setNotifyId(notifyId);
	notifyNew.setNotifyResult(notifyResult);

	SqlSession sqlSession = null;
	try {
		sqlSession = MybatisManager.getSqlSession();
		NotifyMapper notifyMapper = sqlSession.getMapper(NotifyMapper.class);
		int result = notifyMapper.updateByPrimaryKeySelective(notifyNew);
		if (result != 1) {
			MybatisManager.log.warn("修改notify失败");
			return null;
		}
		sqlSession.commit();
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("修改notify异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
	return getNotify(notifyNew.getNotifyId());
}
 
开发者ID:dianbaer,项目名称:epay,代码行数:36,代码来源:NotifyAction.java

示例11: getGroupChatNum

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static long getGroupChatNum(String toTypeId, String chatCreateTime) {
	if (StringUtil.stringIsNull(toTypeId)) {
		return 0;
	}
	Date date = null;
	if (!StringUtil.stringIsNull(chatCreateTime)) {
		date = TimeUtils.stringToDateDay(chatCreateTime);
	}
	SqlSession sqlSession = null;
	try {
		sqlSession = MybatisManager.getSqlSession();
		ChatMapper chatMapper = sqlSession.getMapper(ChatMapper.class);
		ChatCriteria chatCriteria = new ChatCriteria();
		ChatCriteria.Criteria criteria = chatCriteria.createCriteria();
		criteria.andToTypeEqualTo((byte) ChatConfig.TO_TYPE_GROUP);

		criteria.andToTypeIdEqualTo(toTypeId);
		if (date != null) {
			criteria.andChatCreateTimeLessThan(date);
		}
		criteria.andChatStateEqualTo((byte) ChatConfig.CHAT_STATE_EXIST);
		chatCriteria.setOrderByClause("chat_create_time asc");
		long result = chatMapper.countByExample(chatCriteria);
		return result;
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("获取聊天异常", e);
		return 0;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:37,代码来源:ChatAction.java

示例12: testDeleteByIds

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void testDeleteByIds() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        int count = mapper.deleteByIds("1,2,3");
        //查询总数
        Assert.assertEquals(3, count);
        Assert.assertEquals(180, mapper.selectCount(null));
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:godlike110,项目名称:tk-mybatis,代码行数:15,代码来源:TestIds.java

示例13: testDynamicDeleteException

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
 * 主键格式错误
 */
@Test
public void testDynamicDeleteException() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //根据主键删除
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(100));
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:godlike110,项目名称:tk-mybatis,代码行数:16,代码来源:TestDeleteByPrimaryKey.java

示例14: createToken

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Token createToken(String userId) {
	if (StringUtil.stringIsNull(userId)) {
		return null;
	}
	Token token = new Token();
	Date date = new Date();
	token.setTokenCreateTime(date);
	token.setTokenUpdateTime(date);
	Date expireTime = new Date(date.getTime() + CommonConfigUCenter.TOKEN_EXPIRE_TIME);
	token.setTokenExpireTime(expireTime);
	token.setUserId(userId);
	token.setTokenId(IdUtil.getUuid());

	SqlSession sqlSession = null;
	try {
		sqlSession = MybatisManager.getSqlSession();
		TokenMapper tokenMapper = sqlSession.getMapper(TokenMapper.class);
		int result = tokenMapper.insert(token);
		if (result == 0) {
			MybatisManager.log.warn("创建token失败");
			return null;
		}
		sqlSession.commit();
		return token;
	} catch (Exception e) {
		if (sqlSession != null) {
			sqlSession.rollback();
		}
		MybatisManager.log.error("创建token异常", e);
		return null;
	} finally {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:37,代码来源:TokenAction.java

示例15: getChatGroupUserList

import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static List<ChatGroupUser> getChatGroupUserList(String userId, String chatGroupId) {

		SqlSession sqlSession = null;
		List<ChatGroupUser> chatGroupUserList = null;
		try {
			sqlSession = MybatisManager.getSqlSession();
			ChatGroupUserMapper chatGroupUserMapper = sqlSession.getMapper(ChatGroupUserMapper.class);
			ChatGroupUserCriteria chatGroupUserCriteria = new ChatGroupUserCriteria();
			ChatGroupUserCriteria.Criteria criteria = chatGroupUserCriteria.createCriteria();
			if (!StringUtil.stringIsNull(userId)) {
				criteria.andUserIdEqualTo(userId);
			}
			if (!StringUtil.stringIsNull(chatGroupId)) {
				criteria.andChatGroupIdEqualTo(chatGroupId);
			}
			chatGroupUserList = chatGroupUserMapper.selectByExample(chatGroupUserCriteria);
			if (chatGroupUserList == null) {
				MybatisManager.log.warn("通过userId:" + userId + ",chatGroupId:" + chatGroupId + "获取聊天组为空");
			}
		} catch (Exception e) {
			if (sqlSession != null) {
				sqlSession.rollback();
			}
			MybatisManager.log.error("获取聊天组异常", e);
			return null;
		} finally {
			if (sqlSession != null) {
				sqlSession.close();
			}
		}
		return chatGroupUserList;
	}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:33,代码来源:ChatGroupUserAction.java


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