Search in sources :

Example 1 with DatabaseMeta

use of org.nutz.dao.DatabaseMeta 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, dataSource);
        holder.maker = createEntityMaker();
    }
    setRunner(runner);
    setExecutor(executor);
}
Also used : ConnCallback(org.nutz.dao.ConnCallback) NutPojoMaker(org.nutz.dao.impl.sql.NutPojoMaker) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) DatabaseMeta(org.nutz.dao.DatabaseMeta) HashSet(java.util.HashSet)

Aggregations

Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 HashSet (java.util.HashSet)1 ConnCallback (org.nutz.dao.ConnCallback)1 DatabaseMeta (org.nutz.dao.DatabaseMeta)1 NutPojoMaker (org.nutz.dao.impl.sql.NutPojoMaker)1