use of org.nutz.dao.impl.NutDao in project nutz by nutzam.
the class CustomizedSqlsTest method test_dynamic_insert.
@Test
public void test_dynamic_insert() {
pojos.init();
((NutDao) dao).setSqlManager(new FileSqlManager("org/nutz/dao/test/sqls/exec.sqls"));
int platoonId = 23;
try {
pojos.initPlatoon(platoonId);
Sql sql = dao.sqls().create("tank.insert");
sql.vars().set("id", platoonId);
sql.params().set("code", "T1").set("weight", 12);
dao.execute(sql);
sql = dao.sqls().create("tank.insert");
sql.vars().set("id", platoonId);
sql.params().set("code", "T2").set("weight", 13);
dao.execute(sql);
sql = dao.sqls().create("tank.insert");
sql.vars().set("id", platoonId);
sql.params().set("code", "T3").set("weight", 14);
dao.execute(sql);
sql = dao.sqls().create("tank.insert");
sql.vars().set("id", platoonId);
sql.params().set("code", "T4").set("weight", 15);
dao.execute(sql);
TableName.run(platoonId, new Atom() {
public void run() {
assertEquals(4, dao.count(Tank.class));
}
});
} catch (SqlNotFoundException e) {
} finally {
pojos.dropPlatoon(platoonId);
}
}
use of org.nutz.dao.impl.NutDao in project nutz by nutzam.
the class DaoUp method setDataSource.
/**
* 主动设置数据源(连接池)
* @param dataSource 数据源(连接池)
*/
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
setDao(new NutDao(dataSource));
}
use of org.nutz.dao.impl.NutDao in project nutz by nutzam.
the class AnnotationIocLoaderTest method test_ioc_inject_by_setter.
@Test
public void test_ioc_inject_by_setter() throws ObjectLoadException {
AnnotationIocLoader loader = new AnnotationIocLoader(getClass().getPackage().getName());
Logs.get().error(loader.load(null, "issue1060"));
NutIoc ioc = new NutIoc(loader);
// 放个假的
ioc.getIocContext().save("app", "dao", new ObjectProxy(new NutDao()));
ioc.get(Issue1060.class);
ioc.depose();
}
use of org.nutz.dao.impl.NutDao 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.dao.impl.NutDao in project druid by alibaba.
the class TestRollBack method init.
// jdbcUrl = "jdbc:oracle:thin:@a.b.c.d:1521:ocnauto";
// user = "alibaba";
// password = "ccbuauto";
@BeforeClass
public static void init() throws PropertyVetoException, SQLException {
c3p0 = new ComboPooledDataSource();
// c3p0.setDriverClass("oracle.jdbc.driver.OracleDriver");
c3p0.setDriverClass(driver);
c3p0.setJdbcUrl(url);
c3p0.setUser(user);
c3p0.setPassword(password);
druid = new DruidDataSource();
druid.setUrl(url);
druid.setUsername(user);
druid.setPassword(password);
druid.setFilters("stat,trace,encoding");
druid.setDefaultAutoCommit(false);
dao_c3p0 = new NutDao(c3p0);
dao_druid = new NutDao(druid);
if (!dao_c3p0.exists("msg")) {
// 字段长度5
dao_c3p0.execute(Sqls.create("create table msg(message varchar(5))"));
}
}
Aggregations