NutzCN Logo
问答 org.nutz.trans SimpleTransTest 有没有测试类 H2数据库 创建的案例呢
发布于 1925天前 作者 Hamming 1471 次浏览 复制 上一个帖子 下一个帖子
标签:

org.nutz.trans SimpleTransTest 有没有测试类 H2数据库 创建的案例呢

5 回复

org.nutz.trans SimpleTransTest 的测试类执行不通过
有没有h2数据库 连接 创建数据库 增删改查 类似的 测试类 可以做参考

test目录下的nutz-test.properties里面有示例,去掉注释就变h2了

呃 测试方法 似乎 有问题

A
org.nutz.dao.DaoException: !Nutz SQL Error: 'UPDATE t_pet SET name='A',alias='TzKpSNqDJ',age=7,mas=0,birthday='2019-09-16 10:49:15',price=0.0  WHERE id=2'
PreparedStatement: 
'UPDATE t_pet SET name=?,alias=?,age=?,mas=?,birthday=?,price=?  WHERE id=?'
CaseMessage=Unique index or primary key violation: "CONSTRAINT_INDEX_4C ON PUBLIC.T_PET(NAME) VALUES ('A', 1)"; SQL statement:
UPDATE t_pet SET name=?,alias=?,age=?,mas=?,birthday=?,price=?  WHERE id=? [23505-196]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:110)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:65)
	at org.nutz.dao.impl.interceptor.SayHiDaoInterceptor.filter(SayHiDaoInterceptor.java:16)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:63)
	at org.nutz.dao.impl.interceptor.DaoTimeInterceptor.filter(DaoTimeInterceptor.java:23)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:63)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:63)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:163)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:109)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:93)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:79)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:77)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:242)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:254)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:58)
	at org.nutz.dao.impl.NutDao.update(NutDao.java:275)
	at org.nutz.trans.SimpleTransTest$1.run(SimpleTransTest.java:44)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.trans.Trans.exec(Trans.java:132)
	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:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "CONSTRAINT_INDEX_4C ON PUBLIC.T_PET(NAME) VALUES ('A', 1)"; SQL statement:
UPDATE t_pet SET name=?,alias=?,age=?,mas=?,birthday=?,price=?  WHERE id=? [23505-196]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
	at org.h2.message.DbException.get(DbException.java:179)
	at org.h2.message.DbException.get(DbException.java:155)
	at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:103)
	at org.h2.mvstore.db.MVSecondaryIndex.checkUnique(MVSecondaryIndex.java:231)
	at org.h2.mvstore.db.MVSecondaryIndex.add(MVSecondaryIndex.java:190)
	at org.h2.mvstore.db.MVTable.addRow(MVTable.java:705)
	at org.h2.table.Table.updateRows(Table.java:506)
	at org.h2.command.dml.Update.update(Update.java:145)
	at org.h2.command.CommandContainer.update(CommandContainer.java:101)
	at org.h2.command.Command.executeUpdate(Command.java:260)
	at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:207)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:494)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:311)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:96)
	... 46 more
XiaoBai
Disconnected from the target VM, address: '127.0.0.1:64001', transport: 'socket'

Process finished with exit code 0

    @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.setName("A");
        pet2.setName("A");
        // Begin transaction        
        Trans.DEBUG = true;
        try {
            Trans.exec(new Atom() {
                public void run() {
                    dao.update(pet1);
                    System.out.println(dao.fetch(Pet.class, pet1.getId()).getName());
                    dao.update(pet2);
                    //throw Lang.noImplement();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        // End transaction
        System.out.println(dao.fetch(Pet.class, pet1.getId()).getName());
        assertFalse(dao.fetch(Pet.class, pet1.getId()).getName().equals(pet1.getName()));
    }

应该是名称重复了

添加回复
请先登陆
回到顶部