Closed jackmeng2015 closed 9 years ago
我的测试代码
@Test
public void test_update_rollback() {
dao.create(Pet.class, true);
dao.insert(Pet.create("XiaoBai"));
dao.insert(Pet.create("XiaoHei"));
final Pet pet1 = dao.fetch(Pet.class,"XiaoBai");
final Pet pet2 = dao.fetch(Pet.class,"XiaoHei");
pet1.setNickName("BaiBai");
pet2.setNickName("HeiHei");
// Begin transaction
try {
Trans.exec(new Atom(){
public void run() {
dao.update(pet1);
dao.update(pet2);
throw Lang.noImplement();
}
});
}
catch (Exception e) {
e.printStackTrace();
}
// End transaction
assertNotEquals(dao.fetch(Pet.class, pet1.getId()).getNickName(), pet1.getNickName());
}
测试环境是win7 x86 及 sqlserver 2005 exp, 驱动版本4.1
日志如下
ALL Nutz Log via Log4jLogAdapter
2015-03-27 20:46:51,912 org.nutz.log.Logs.<clinit>(Logs.java:20) INFO - Nutz is licensed under the Apache License, Version 2.0 .
Report bugs : https://github.com/nutzam/nutz/issues
2015-03-27 20:46:52,302 org.nutz.resource.Scans.<init>(Scans.java:484) DEBUG - Locations for Scans:
[JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\org.apache.taglibs.standard.glassfish_1.2.0.v201004190952.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\oracle_ojdbc6.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\javax.el_2.1.0.v201004190952.jar], FileSystemResourceLocation [root=H:\strato_work\Nutz2], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\servlet-api-2.5.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\javax.servlet.jsp_2.1.0.v201004190952.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\com.sun.el_1.0.0.v201004190952.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\commons-dbcp-1.4.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\javax.servlet.jsp.jstl_1.2.0.v201004190952.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\commons-logging-1.1.1.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\commons-pool-1.5.4.jar], FileSystemResourceLocation [root=H:\eclipse\configuration\org.eclipse.osgi\204\0\.cp], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\ecj-3.8.1.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\cache-annotations-ri-common-1.0.0.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\sqljdbc41.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\jetty-all-server-7.6.4.v20120524.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\h2-1.3.154.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\cache-api-1.0.0.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\cache-ri-impl-1.0.0.jar], JarResourceLocation [jarPath=H:\eclipse\plugins\org.junit_4.11.0.v201303080030\junit.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\jetty\org.apache.jasper.glassfish_2.1.0.v201007080150.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\mysql-connector-java-5.1.23-bin.jar], JarResourceLocation [jarPath=H:\strato_work\Nutz2\build\deps\log4j-1.2.14.jar], JarResourceLocation [jarPath=H:\eclipse\plugins\org.hamcrest.core_1.3.0.v201303031735.jar], FileSystemResourceLocation [root=H:\eclipse\configuration\org.eclipse.osgi\205\0\.cp], FileSystemResourceLocation [root=H:\strato_work\Nutz2\target\classes]]
2015-03-27 20:46:52,302 org.nutz.resource.Scans.scan(Scans.java:228) DEBUG - Found 1 resource by src( org/nutz/dao/test/meta/pojo.js ) , regex( ^(.+[.])(js|json)$ )
2015-03-27 20:46:52,318 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:44) DEBUG - loading ioc js config from [pojo.js]
2015-03-27 20:46:52,318 org.nutz.ioc.loader.json.JsonLoader.<init>(JsonLoader.java:52) DEBUG - Loaded 5 bean define from path=[org/nutz/dao/test/meta/pojo.js] --> [sqls, metas, dao, config, dataSource]
2015-03-27 20:46:52,318 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2015-03-27 20:46:52,318 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
2015-03-27 20:46:52,318 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=dao
2015-03-27 20:46:52,333 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'dao'<interface org.nutz.dao.Dao>
2015-03-27 20:46:52,349 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.nutz.dao.impl.NutDao , no config to enable AOP for this type.
2015-03-27 20:46:52,349 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'dao' to [app]
2015-03-27 20:46:52,349 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'dataSource'<>
2015-03-27 20:46:52,349 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
2015-03-27 20:46:52,349 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=dataSource
2015-03-27 20:46:52,411 org.nutz.castor.Castors.reload(Castors.java:116) DEBUG - Using 91 castor for Castors
2015-03-27 20:46:52,411 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'dataSource'<>
2015-03-27 20:46:52,411 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.apache.commons.dbcp.BasicDataSource , no config to enable AOP for this type.
2015-03-27 20:46:52,411 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'dataSource' to [app]
2015-03-27 20:46:52,521 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'config'<>
2015-03-27 20:46:52,521 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
2015-03-27 20:46:52,521 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=config
2015-03-27 20:46:52,521 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'config'<>
2015-03-27 20:46:52,521 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.nutz.ioc.impl.PropertiesProxy , no config to enable AOP for this type.
2015-03-27 20:46:52,521 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'config' to [app]
2015-03-27 20:46:52,521 org.nutz.resource.Scans.scan(Scans.java:228) DEBUG - Found 1 resource by src( nutz-test.properties ) , regex( ^.+[.]properties$ )
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'config'<>
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'config'<>
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'config'<>
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'sqls'<>
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
2015-03-27 20:46:52,536 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=sqls
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'sqls'<>
2015-03-27 20:46:52,536 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.nutz.dao.impl.FileSqlManager , no config to enable AOP for this type.
2015-03-27 20:46:52,536 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'sqls' to [app]
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'dataSource'<>
2015-03-27 20:46:52,536 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'sqls'<>
2015-03-27 20:46:52,583 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:23) INFO - Init file-pool by: C:\Users\wendal/.nutz/tmp/dao/ [200000]
2015-03-27 20:46:52,583 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:37) DEBUG - file-pool.home: 'C:\Users\wendal\.nutz\tmp\dao'
2015-03-27 20:46:52,583 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:66) INFO - file-pool.cursor: 120
2015-03-27 20:46:52,583 org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:85) DEBUG - Jdbcs init complete
2015-03-27 20:46:52,583 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:98) INFO - Get Connection from DataSource for JdbcExpert
2015-03-27 20:46:52,895 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:165) DEBUG - JDBC Driver --> 4.1.5605.100
2015-03-27 20:46:52,895 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:166) DEBUG - JDBC Name --> Microsoft JDBC Driver 4.1 for SQL Server
2015-03-27 20:46:52,911 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:174) DEBUG - Database info --> SQLSERVER:[Microsoft SQL Server - 9.00.1399]
2015-03-27 20:46:52,911 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'metas'<class org.nutz.dao.test.meta.Pojos>
2015-03-27 20:46:52,911 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
2015-03-27 20:46:52,911 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=metas
2015-03-27 20:46:52,911 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'metas'<class org.nutz.dao.test.meta.Pojos>
2015-03-27 20:46:52,911 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.nutz.dao.test.meta.Pojos , no config to enable AOP for this type.
2015-03-27 20:46:52,911 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'metas' to [app]
2015-03-27 20:46:52,911 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'dao'<>
2015-03-27 20:46:52,911 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'dao'<>
2015-03-27 20:46:52,990 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_company
2015-03-27 20:46:53,005 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_company' doesn't exist!
2015-03-27 20:46:53,005 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_company(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
PRIMARY KEY (id)
)
2015-03-27 20:46:53,005 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_master
2015-03-27 20:46:53,021 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_master' doesn't exist!
2015-03-27 20:46:53,021 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_master(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
comId NUMERIC(8),
PRIMARY KEY (id)
)
2015-03-27 20:46:53,036 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_cat
2015-03-27 20:46:53,036 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_cat' doesn't exist!
2015-03-27 20:46:53,036 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_cat(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
masterId NUMERIC(8),
PRIMARY KEY (id)
)
2015-03-27 20:46:53,036 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - INSERT INTO trans_cat(name,masterId) VALUES(?,?)
| 1 | 2 |
|----|---|
| xb | 0 |
For example:> "INSERT INTO trans_cat(name,masterId) VALUES('xb',0) "
2015-03-27 20:46:53,068 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT @@IDENTITY as id
2015-03-27 20:46:53,068 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_company
2015-03-27 20:46:53,068 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_company' doesn't exist!
2015-03-27 20:46:53,068 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_company(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
PRIMARY KEY (id)
)
2015-03-27 20:46:53,068 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_master
2015-03-27 20:46:53,083 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_master' doesn't exist!
2015-03-27 20:46:53,083 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_master(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
comId NUMERIC(8),
PRIMARY KEY (id)
)
2015-03-27 20:46:53,083 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE trans_cat
2015-03-27 20:46:53,083 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 'trans_cat' doesn't exist!
2015-03-27 20:46:53,083 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE trans_cat(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
masterId NUMERIC(8),
PRIMARY KEY (id)
)
2015-03-27 20:46:53,083 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - INSERT INTO trans_cat(name,masterId) VALUES(?,?)
| 1 | 2 |
|----|---|
| xb | 0 |
For example:> "INSERT INTO trans_cat(name,masterId) VALUES('xb',0) "
2015-03-27 20:46:53,083 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT @@IDENTITY as id
2015-03-27 20:46:53,099 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - DROP TABLE t_pet
2015-03-27 20:46:53,099 org.nutz.dao.impl.jdbc.AbstractJdbcExpert.setupEntityField(AbstractJdbcExpert.java:102) DEBUG - Table 't_pet' doesn't exist!
2015-03-27 20:46:53,099 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - CREATE TABLE t_pet(
id NUMERIC(8) IDENTITY,
name VARCHAR(50) UNIQUE NOT NULL,
alias VARCHAR(50),
age NUMERIC(8),
mas NUMERIC(8),
birthday DATETIME,
price float,
PRIMARY KEY (id)
)
2015-03-27 20:46:53,114 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - Create UNIQUE Index t_pet_name_masterId ON t_pet(name,mas)
2015-03-27 20:46:53,114 org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:313) DEBUG - Create Index t_pet_name_age ON t_pet(name,age)
2015-03-27 20:46:53,114 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - INSERT INTO t_pet(name,alias,age,mas,birthday,price) VALUES(?,?,?,?,?,?)
| 1 | 2 | 3 | 4 | 5 | 6 |
|---------|-----------|---|---|---------------------|-----|
| XiaoBai | NAFNKNUet | 6 | 0 | 2015-03-27 20:46:53 | 0.0 |
For example:> "INSERT INTO t_pet(name,alias,age,mas,birthday,price) VALUES('XiaoBai','NAFNKNUet',6,0,'2015-03-27 20:46:53',0.0) "
2015-03-27 20:46:53,114 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT @@IDENTITY as id
2015-03-27 20:46:53,114 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - INSERT INTO t_pet(name,alias,age,mas,birthday,price) VALUES(?,?,?,?,?,?)
| 1 | 2 | 3 | 4 | 5 | 6 |
|---------|-------|---|---|---------------------|-----|
| XiaoHei | LosVV | 5 | 0 | 2015-03-27 20:46:53 | 0.0 |
For example:> "INSERT INTO t_pet(name,alias,age,mas,birthday,price) VALUES('XiaoHei','LosVV',5,0,'2015-03-27 20:46:53',0.0) "
2015-03-27 20:46:53,130 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT @@IDENTITY as id
2015-03-27 20:46:53,130 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_pet WHERE name=?
| 1 |
|---------|
| XiaoBai |
For example:> "SELECT * FROM t_pet WHERE name='XiaoBai'"
2015-03-27 20:46:53,130 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_pet WHERE name=?
| 1 |
|---------|
| XiaoHei |
For example:> "SELECT * FROM t_pet WHERE name='XiaoHei'"
2015-03-27 20:46:53,130 org.nutz.trans.Trans._begain(Trans.java:58) DEBUG - Start New Transaction id=0, level=2
2015-03-27 20:46:53,130 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - UPDATE t_pet SET name=?,alias=?,age=?,mas=?,birthday=?,price=? WHERE id=?
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---------|--------|---|---|---------------------|-----|---|
| XiaoBai | BaiBai | 6 | 0 | 2015-03-27 20:46:53 | 0.0 | 1 |
For example:> "UPDATE t_pet SET name='XiaoBai',alias='BaiBai',age=6,mas=0,birthday='2015-03-27 20:46:53',price=0.0 WHERE id=1"
java.lang.RuntimeException: Not implement yet!
2015-03-27 20:46:53,146 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - UPDATE t_pet SET name=?,alias=?,age=?,mas=?,birthday=?,price=? WHERE id=?
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---------|--------|---|---|---------------------|-----|---|
| XiaoHei | HeiHei | 5 | 0 | 2015-03-27 20:46:53 | 0.0 | 2 |
For example:> "UPDATE t_pet SET name='XiaoHei',alias='HeiHei',age=5,mas=0,birthday='2015-03-27 20:46:53',price=0.0 WHERE id=2"
2015-03-27 20:46:53,146 org.nutz.trans.Trans._rollback(Trans.java:102) DEBUG - Transaction rollback id=0, count=0
2015-03-27 20:46:53,146 org.nutz.trans.Trans._depose(Trans.java:87) DEBUG - Transaction depose id=0, count=0
2015-03-27 20:46:53,146 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_pet WHERE id=?
| 1 |
|---|
| 1 |
For example:> "SELECT * FROM t_pet WHERE id=1"
at org.nutz.lang.Lang.noImplement(Lang.java:77)
at org.nutz.trans.SimpleTransTest$1.run(SimpleTransTest.java:44)
at org.nutz.trans.Trans.exec(Trans.java:165)
at org.nutz.trans.Trans.exec(Trans.java:123)
at org.nutz.trans.SimpleTransTest.test_update_rollback(SimpleTransTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
我的测试结果是pass
附上Pet类,取自于test目录
package org.nutz.dao.test.meta;
import java.sql.Timestamp;
import org.nutz.dao.DB;
import org.nutz.dao.entity.annotation.*;
import org.nutz.lang.Strings;
import org.nutz.lang.random.R;
import org.nutz.lang.random.StringGenerator;
@Table("t_pet")
@TableIndexes({@Index(name = "t_pet_name_masterId", unique = true,
fields = {"name", "masterId"}),
@Index(name = "t_pet_name_age", fields = {"name", "age"},
unique = false)})
public class Pet {
private static StringGenerator sg = R.sg(5, 10);
public static Pet create(String name) {
Pet pet = new Pet();
pet.setName(name);
pet.setAge(R.random(3, 10));
pet.setNickName(sg.next());
pet.setBirthday(new Timestamp(System.currentTimeMillis()));
return pet;
}
public static Pet[] create(int num) {
Pet[] pets = new Pet[num];
for (int i = 0; i < num; i++)
pets[i] = create("pet_" + Strings.fillHex(i, 2));
return pets;
}
@Id
@Next({@SQL(db = DB.PSQL, value = "SELECT currval('$table$_id_seq')")})
private int id;
@Name
private String name;
@Column("alias")
private String nickName;
@Column
private int age;
@Column("mas")
private int masterId;
@Column
private Timestamp birthday;
@Column
private float price;
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public int getId() {
return id;
}
public Pet setId(int id) {
this.id = id;
return this;
}
public int getMasterId() {
return masterId;
}
public void setMasterId(int masterId) {
this.masterId = masterId;
}
public String getName() {
return name;
}
public Pet setName(String name) {
this.name = name;
return this;
}
public String getNickName() {
return nickName;
}
public Pet setNickName(String nickName) {
this.nickName = nickName;
return this;
}
public int getAge() {
return age;
}
public Pet setAge(int age) {
this.age = age;
return this;
}
public Timestamp getBirthday() {
return birthday;
}
public void setBirthday(Timestamp birthday) {
this.birthday = birthday;
}
public String toString() {
return name;
}
}
我试过你的代码了,成功执行了dao.update(person1);和dao.update(person2);之后再执行throw Lang.noImplement();是可以整个事务回滚的,都是如果“dao.update(person2);// 违反了 UNIQUE KEY 约束,抛出异常”本身SQL出问题了,是没办法让第一句dao.update(person1);也回滚
@Test
public void testTransaction2() {
final Person person1 = dao.fetch(Person.class, 1);
final Person person2 = dao.fetch(Person.class, 2);
person1.setAge(100);
person2.setAge(100);
// person2.setName("ABC");
Trans.DEBUG = true;
try{
Trans.exec(new Atom() {
public void run() {
dao.update(person1);
dao.update(person2);// 违反了 UNIQUE KEY 约束,抛出异常
throw Lang.noImplement();
}
});
}catch(Exception e){
e.printStackTrace();
}
}
最后结论是druid 0.2.2 的bug
代码如下:
控制台输出日志如下: