use of org.nutz.dao.impl.sql.NutPojoMaker in project nutz by nutzam.
the class DaoSupport method setDataSource.
public void setDataSource(DataSource ds, boolean isLazy) {
if (null != dataSource)
if (log.isWarnEnabled())
log.warn("Replaced a running dataSource!");
dataSource = ds;
if (expert == null)
expert = Jdbcs.getExpert(ds);
log.debug("select expert : " + expert.getClass().getName());
pojoMaker = new NutPojoMaker(expert);
meta = new DatabaseMeta();
final Set<String> keywords = new HashSet<String>(Daos.sql2003Keywords());
run(new ConnCallback() {
public void invoke(Connection conn) throws Exception {
try {
DatabaseMetaData dmd = conn.getMetaData();
meta.setProductName(dmd.getDatabaseProductName());
meta.setVersion(dmd.getDatabaseProductVersion());
log.debug("JDBC Driver --> " + dmd.getDriverVersion());
log.debug("JDBC Name --> " + dmd.getDriverName());
if (!Strings.isBlank(dmd.getURL()))
log.debug("JDBC URL --> " + dmd.getURL());
if (dmd.getDriverName().contains("mariadb") || dmd.getDriverName().contains("sqlite")) {
log.warn("Auto-select fetch size to Integer.MIN_VALUE, enable for ResultSet Streaming");
SqlContext.DEFAULT_FETCH_SIZE = Integer.MIN_VALUE;
}
String tmp = dmd.getSQLKeywords();
if (tmp != null) {
for (String keyword : tmp.split(",")) {
keywords.add(keyword.toUpperCase());
}
}
expert.checkDataSource(conn);
} catch (Exception e) {
log.info("something wrong when checking DataSource", e);
}
}
});
if (log.isDebugEnabled())
log.debug("Database info --> " + meta);
expert.setKeywords(keywords);
if (!isLazy) {
holder = new EntityHolder(this.expert, new Callback<ConnCallback>() {
public void invoke(ConnCallback obj) {
run(obj);
}
});
holder.maker = createEntityMaker();
}
setRunner(runner);
setExecutor(executor);
}
Aggregations