batchInsertMultipleFollowersAsFixture(names);
String nameSuffix = "Wang";
for (String name : names) {
if (name.startsWith("A")) {
Follower follower = (Follower) getSqlMapClientTemplate().queryForObject(
"com.alibaba.cobar.client.entities.Follower.finaByName", name);
assertNotNull(follower);
follower.setName(follower.getName() + nameSuffix);
getSqlMapClientTemplate().update(
"com.alibaba.cobar.client.entities.Follower.update", follower);
Long id = follower.getId();
follower = null;
follower = (Follower) getSqlMapClientTemplate().queryForObject(
"com.alibaba.cobar.client.entities.Follower.finaByName", name);
assertNull(follower);
follower = (Follower) getSqlMapClientTemplate().queryForObject(
"com.alibaba.cobar.client.entities.Follower.load", id);
assertNotNull(follower);
assertEquals(name + nameSuffix, follower.getName());
} else {
String sql = "select * from followers where name=?";
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Follower f = new Follower();
f.setId(rs.getLong(1));
f.setName(rs.getString(2));
return f;
}
};
Follower follower = (Follower) jt2m.queryForObject(sql, new Object[] { name },
rowMapper);
assertNotNull(follower);
follower.setName(follower.getName() + nameSuffix);
getSqlMapClientTemplate().update(
"com.alibaba.cobar.client.entities.Follower.update", follower);
Long id = follower.getId();
follower = null;
try {
follower = (Follower) jt2m
.queryForObject(sql, new Object[] { name }, rowMapper);
fail();
} catch (DataAccessException e) {
assertTrue(e instanceof EmptyResultDataAccessException);
}
follower = (Follower) jt2m.queryForObject("select * from followers where id=?",
new Object[] { id }, rowMapper);
assertNotNull(follower);
assertEquals(name + nameSuffix, follower.getName());
}
}
}