Search in sources :

Example 11 with DaoException

use of org.nutz.dao.DaoException in project nutz by nutzam.

the class BatchTransTest method try_insert_static_objects_by_many_many.

@Test
public void try_insert_static_objects_by_many_many() {
    pojos.init();
    final Base b = Base.make("B");
    b.setFighters(new ArrayList<Fighter>());
    TableName.run(1, new Atom() {

        public void run() {
            Trans.exec(new Atom() {

                public void run() {
                    dao.insert(Country.make("A"));
                    try {
                        dao.insert(Country.make("A"));
                    } catch (DaoException e) {
                    }
                    dao.insert(Country.make("C"));
                    dao.insert(Country.make("D"));
                }
            });
            assertEquals(3, dao.count(Country.class));
        }
    });
}
Also used : Fighter(org.nutz.dao.test.meta.Fighter) DaoException(org.nutz.dao.DaoException) Base(org.nutz.dao.test.meta.Base) Test(org.junit.Test)

Example 12 with DaoException

use of org.nutz.dao.DaoException in project nutz by nutzam.

the class SimpleDaoTest method run_2_sqls_with_error.

@Test
public void run_2_sqls_with_error() {
    assertEquals(0, dao.count(Pet.class));
    Sql sql1 = Sqls.create("INSERT INTO t_pet (name) VALUES ('A')");
    Sql sql2 = Sqls.create("INSERT INTO t_pet (nocol) VALUES ('B')");
    try {
        dao.execute(sql1, sql2);
        fail();
    } catch (DaoException e) {
    }
    assertEquals(0, dao.count(Pet.class));
}
Also used : DaoException(org.nutz.dao.DaoException) Issue1163Pet(org.nutz.dao.test.meta.issue1163.Issue1163Pet) Pet(org.nutz.dao.test.meta.Pet) PojoSql(org.nutz.dao.test.meta.issue1074.PojoSql) Sql(org.nutz.dao.sql.Sql) Test(org.junit.Test)

Aggregations

DaoException (org.nutz.dao.DaoException)12 SQLException (java.sql.SQLException)4 Test (org.junit.Test)3 Connection (java.sql.Connection)2 Pojo (org.nutz.dao.sql.Pojo)2 Sql (org.nutz.dao.sql.Sql)2 Pet (org.nutz.dao.test.meta.Pet)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Savepoint (java.sql.Savepoint)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 EntityField (org.nutz.dao.entity.EntityField)1 MappingField (org.nutz.dao.entity.MappingField)1 Column (org.nutz.dao.entity.annotation.Column)1 Id (org.nutz.dao.entity.annotation.Id)1 ManyMany (org.nutz.dao.entity.annotation.ManyMany)1 Name (org.nutz.dao.entity.annotation.Name)1 One (org.nutz.dao.entity.annotation.One)1 ManyLinkField (org.nutz.dao.impl.entity.field.ManyLinkField)1