cn.wizzer.app.code.commons.builder.TableDescLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wk-code-generator-nb Show documentation
Show all versions of wk-code-generator-nb Show documentation
java web development framework, base on nutz
package cn.wizzer.app.code.commons.builder;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.impl.NutDao;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.Ioc;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 根据数据库结构生成model,service,controller,views
* Created by wizzer on 2017/1/23.
*/
public class TableDescLoader extends Loader {
@Override
public Map loadTables(Ioc ioc,
String basePackageName, String basePath, String baseUri, String servPackageName, String modPackageName) throws SQLException {
DataSource ds = ioc.get(DataSource.class);
Dao dao = new NutDao(ds);
Sql sql = Sqls.create("select database()");
sql.setCallback(new SqlCallback() {
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
if (rs.next()) {
return rs.getString(1);
}
return null;
}
});
dao.execute(sql);
String database = sql.getString();
Sql tableSchemaSql = Sqls.create("select * from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = '"
+ database + "'");
tableSchemaSql.setCallback(new SqlCallback() {
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy