Skip to content

Instantly share code, notes, and snippets.

@wendal
Created January 28, 2012 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/1694549 to your computer and use it in GitHub Desktop.
Save wendal/1694549 to your computer and use it in GitHub Desktop.
Nutz_fastinsert_rollback
//For github issue 131
@Test
public void test_fastInsert_rollback() {
dao.create(Pet.class, true);
final List<Pet> pets = new ArrayList<Pet>();
for (int i = 0; i < 100; i++) {
Pet u = new Pet();
u.setName("XXXX" + i);
pets.add(u);
}
try {
Trans.exec(new Molecule<Object>() {
@Override
public void run() {
dao.fastInsert(pets);
throw new RuntimeException();
}
});
} catch (Throwable e) {
e.printStackTrace();
}
assertEquals(0, dao.count(Pet.class));
}
//For github issue 131
@Test
public void test_fastInsert_rollback_jdbc() {
dao.create(Pet.class, true);
try {
Trans.exec(new Molecule<Object>() {
@Override
public void run() {
dao.run(new ConnCallback() {
@Override
public void invoke(Connection conn) throws Exception {
PreparedStatement ps = conn.prepareStatement("INSERT INTO t_pet(name) VALUES(?)");
for (int i = 0; i < 100; i++) {
ps.setString(1, "XXXXX" + i);
ps.addBatch();
}
ps.execute();
}
});
throw new RuntimeException();
}
});
} catch (Throwable e) {
e.printStackTrace();
}
assertEquals(0, dao.count(Pet.class));
}
@cnyangqi
Copy link

cnyangqi commented Feb 6, 2012

fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment