use of org.nutz.trans.Atom in project nutz by nutzam.
the class PsTest method main.
/**
* 测试新的Dao实现在postgresql下的表现
*/
public static void main(String[] args) throws Throwable {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUsername("postgres");
ds.setPassword("123456");
ds.setUrl("jdbc:postgresql:test");
ds.setDefaultAutoCommit(false);
final NutDao dao = new NutDao(ds);
TableName.run(1, new Atom() {
public void run() {
Trans.exec(new Atom() {
public void run() {
dao.create(Country.class, true);
System.out.println("------------???");
dao.insert(Country.make("A"));
try {
System.out.println("---------------------");
dao.insert(Country.make("A"));
System.out.println("+++++++++++++++++++++++++++++++++++");
} catch (DaoException e) {
}
try {
dao.insert(Country.make("C"));
} catch (Throwable e) {
System.out.println("天啊,还是报错!!");
}
}
});
}
});
Connection conn = ds.getConnection();
conn.prepareStatement("insert into dao_country(name,detail) values('ABC','CC')").execute();
try {
conn.prepareStatement("insert into dao_country(name,detail) values('ABC','CC')").execute();
} catch (Exception e) {
}
conn.prepareStatement("insert into dao_country(name,detail) values('CC','CC')").execute();
System.out.println("竟然能通过??!!");
conn.commit();
}
use of org.nutz.trans.Atom in project nutz by nutzam.
the class UploadingSpeedTest method main.
public static void main(String[] args) {
if (0 == args.length) {
System.err.println("Lack files directory!");
System.exit(0);
}
File dir = Files.findFile(args[0]);
if (null == dir) {
System.err.println("Fail to found directory: " + args[0]);
System.exit(0);
}
final Uploading up = UploadUnit.TYPE.born();
final UploadingContext uc = UploadingContext.create("~/nutz/unit/uploadtmp");
File[] files = dir.listFiles();
final MockHttpServletRequest req = request().setInputStream(insmulti("UTF-8", files));
req.setSession(session(context()));
req.init();
Object monLock = new Object();
int monInterval = 2000;
UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
Thread monThread = new Thread(mon, "UploadingMonitor");
monThread.start();
out.println("Begin...");
Stopwatch sw = null;
try {
sw = Stopwatch.run(new Atom() {
public void run() {
try {
up.parse(req, uc);
} catch (UploadException e) {
throw Lang.wrapThrow(e);
}
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
mon.stop();
out.println("\n...Done!");
if (null != sw)
out.println(sw);
}
}
use of org.nutz.trans.Atom in project nutz by nutzam.
the class TransactionTest method testRollback.
@Test
public void testRollback() {
// In transaction
try {
Trans.exec(new Atom() {
public void run() {
Company com = Company.create("dtri");
Master m = Master.create("zzh", com);
Cat c1 = Cat.create("XiaoBai", m);
Cat c2 = Cat.create("Tony", m);
comService.dao().insert(com);
assertEquals(1, dao.count(Company.class, null));
m.setComId(com.getId());
masterService.dao().insert(m);
assertEquals(1, dao.count(Master.class, null));
c1.setMasterId(m.getId());
c2.setMasterId(m.getId());
catService.dao().insert(c1);
catService.dao().insert(c2);
assertEquals(2, dao.count(Cat.class, null));
throw new RuntimeException("Stop!!!");
}
});
fail();
} catch (Exception e) {
assertEquals(0, dao.count(Company.class, null));
assertEquals(0, dao.count(Master.class, null));
assertEquals(0, dao.count(Cat.class, null));
assertEquals(0, Trans.count.get().intValue());
assertNull(Trans.get());
}
}
use of org.nutz.trans.Atom in project nutz by nutzam.
the class FieldFilterTest method test_update_by_filter.
@Test
public void test_update_by_filter() {
final Pet p = dao.fetch(Pet.class, "xb");
p.setNickName("XiaoBai");
FieldFilter.create(Pet.class, "id|name").run(new Atom() {
public void run() {
dao.update(p);
}
});
Pet p2 = dao.fetch(Pet.class, p.getId());
assertNull(p2.getNickName());
}
use of org.nutz.trans.Atom in project nutz by nutzam.
the class InsertTest method test_insert_by_fieldfilter.
@Test
public void test_insert_by_fieldfilter() {
dao.create(Pet.class, true);
final Pet pet = Pet.create("xb");
pet.setNickName("xiaobai");
FieldFilter.create(Pet.class, "^id|name$").run(new Atom() {
public void run() {
dao.insert(pet);
}
});
Pet xb = dao.fetch(Pet.class, "xb");
assertNull(xb.getNickName());
}
Aggregations