1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
@ContextConfiguration(locations = { " mes fichiers de conf spring ..." })
public class TransactionTest extends AbstractTransactionalJUnit4SpringContextTests {
protected JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test
public void test() throws InterruptedException {
String req = "select num from table1";
List<Integer> nums = jdbcTemplate.queryForList(req, Integer.class);
for (Integer i : nums) {
Thread.sleep(5000);
this.transInsert(i);
}
}
// Je veux qu'à chaque insert, il y ait un commit
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(false)
public void transInsert(int i) {
String req = "insert into table2 values (?)";
jdbcTemplate.update(req, i);
}
} |
Partager