use of com.free.framework.code.tools.model.Table in project free-framework by a601942905git.
the class DataBase2File method genFile.
/**
* 递归生成所有文件代码,子表可以重叠
*
* @param tb
* @param module
* @return
*/
private StringBuffer genFile(Table tb, Module module) {
// 生成entity
generateEntityFile(tb, module);
// 生成dao
generateDaoFile(tb, module);
// 生成service
generateServiceFile(tb, module);
// 生成action
generateActionFile(tb, module);
// generateViewFile(tb,module);//生成view
// 生成jsp文件
generateJSPViewFile(tb, module);
StringBuffer sb = new StringBuffer();
// 若是使用dorado框架,则生成model的数据块
if ("dorado".equals(module.getFramework())) {
String modleString = (generateDoradoModelString(tb, module));
sb.append(modleString);
if (!tb.getSubTables().isEmpty()) {
for (Table subTb : tb.getSubTables()) {
sb.append(genFile(subTb, module));
}
}
}
// System.out.println(sb.toString());
return sb;
}
use of com.free.framework.code.tools.model.Table in project free-framework by a601942905git.
the class DataBase2File method generateFiles.
/**
* 主方法,反转生成相关文件
*
* @throws IOException
* @throws ClassNotFoundException
* @throws SQLException
*/
public void generateFiles() throws IOException, ClassNotFoundException, SQLException {
System.out.println("Generating...");
Long start = System.currentTimeMillis();
// 根据数据库类型获取数据库实例
tableService = TableServiceFactory.getInstance(config.getDb().getDbType());
// 设置数据库实例的配置信息
tableService.setConfig(config);
// 加载数据库驱动
Class.forName(config.getDb().getDriver());
// 连接数据库
Connection con = DriverManager.getConnection(config.getDb().getUrl(), config.getDb().getUser(), config.getDb().getPwd());
// 加载模块信息
for (Module module : config.getModules()) {
System.out.println("module=" + module.getName());
// 如果没有配置数据表,则默认加载模块名为前缀的所有数据表
if (module.getTables() == null || module.getTables().isEmpty()) {
// 获取对应数据库中所有的表
module.setTables(tableService.getAllTables(module.getName() + "%"));
}
// 系统的model文件
StringBuffer sbModel = new StringBuffer();
if (module.getTables() != null) {
for (TableConf tbConf : module.getTables()) {
tbConf.setPrefix(module.getPrefix());
// 获取一个表的相关信息同时设置模块名称
Table table = tableService.getTable(tbConf, module, con);
genFile(table, module);
}
}
// System.out.println(sbModel.toString());
if ("dorado".equals(module.getFramework())) {
// 生成model文件
writeModelFile(module.getName().split("/")[0] + ".model.xml", sbModel.toString());
}
}
con.close();
ZipUtil.zip(config.getBaseDir(), config.getBaseDir() + ".zip");
Long end = System.currentTimeMillis();
System.out.println("Generate Success! total time = " + (end - start));
System.out.println("Please check: " + config.getBaseDir());
}
use of com.free.framework.code.tools.model.Table in project free-framework by a601942905git.
the class MysqlTableService method getTable.
/**
* 获取指定表信息并封装成Table对象
* @param tbConf
* @param module
* @param con
*/
public Table getTable(TableConf tbConf, Module module, Connection con) throws SQLException {
String tableName = tbConf.getName();
Table table = new Table();
table.setTableFullName(tableName);
table.setTableName(tableName);
// 如果设置了表的前缀,则去掉表的前缀
if (module.isDeleteTablePrefix() && !CodeUtil.isEmpty(tbConf.getPrefix())) {
table.setTableName(tableName.toLowerCase().replaceFirst(tbConf.getPrefix(), ""));
}
System.out.println("==表信息===" + tbConf);
// 设置模块名称
module.setName(CodeUtil.getModuleByTableName(tableName));
// 获取表各字段的信息
getTableColumns(table, con);
table.setPrimaryKey(getTablePrimaryKey(tableName, con));
System.out.println("========table.getPrimaryKey()========" + table.getPrimaryKey() + "=====" + tableName);
table.setPrimaryProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(table.getPrimaryKey()));
table.setRemark(getTableRemark(tableName, con));
table.setPrimaryKeyType(getColumnType(table, table.getPrimaryKey()));
table.setPrimaryPropertyType(CodeUtil.convertType(table.getPrimaryKeyType()));
table.setPrimaryCamelProperty(CodeUtil.convertToCamelCase(table.getPrimaryKey()));
// 根据表名获取实体类名称 如:表名称为free_user去掉前缀之后为user,转换之后为User
table.setEntityCamelName(CodeUtil.convertToCamelCase(table.getTableName()));
// 根据表名获取实体类名称参数 如:User转换之后为user
table.setEntityCamelParamName(CodeUtil.firstLetterToLowerCase(table.getEntityCamelName()));
/**
*********************************此处原本的处理方式是将首字母小写,由于不满足,所以改成了首字母大写***********************************
*/
table.setEntityName(CodeUtil.convertToCamelCase(table.getTableName()));
table.setEntityParamName(CodeUtil.firstLetterToLowerCase(table.getEntityName()));
table.setModule(module);
// 设置子表的entity属性
if (!tbConf.getSubTables().isEmpty()) {
List<Table> subTables = new ArrayList<Table>();
for (TableConf tc : tbConf.getSubTables()) {
Table tb = getTable(tc, module, con);
tb.setParentProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(tc.getParentField()));
tb.setRefType(tc.getRefType());
subTables.add(tb);
}
table.setSubTables(subTables);
}
return table;
}
use of com.free.framework.code.tools.model.Table in project free-framework by a601942905git.
the class OracleTableService method getTable.
/**
* 获取指定表信息并封装成Table对象
* @param tbConf
* @param module
* @param con
*/
public Table getTable(TableConf tbConf, Module module, Connection con) throws SQLException {
String tableName = tbConf.getName();
Table table = new Table();
table.setTableFullName(tableName);
table.setTableName(tableName);
if (module.isDeleteTablePrefix() && !CodeUtil.isEmpty(tbConf.getPrefix())) {
table.setTableName(tableName.toLowerCase().replaceFirst(tbConf.getPrefix().toLowerCase(), ""));
}
System.out.println(tbConf);
// 获取表各字段的信息
getTableColumns(table, con);
table.setPrimaryKey(getTablePrimaryKey(tableName, con));
table.setPrimaryProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(table.getPrimaryKey()));
table.setRemark(getTableRemark(tableName, con));
table.setPrimaryKeyType(getColumnType(table, table.getPrimaryKey()));
table.setPrimaryPropertyType(CodeUtil.convertType(table.getPrimaryKeyType()));
table.setPrimaryCamelProperty(CodeUtil.convertToCamelCase(table.getPrimaryKey()));
table.setEntityCamelName(CodeUtil.isEmpty(tbConf.getEntityName()) ? CodeUtil.convertToCamelCase(table.getTableName()) : tbConf.getEntityName());
table.setEntityName(CodeUtil.convertToFirstLetterLowerCaseCamelCase(table.getTableName()));
table.setModule(module);
// 设置子表的entity属性
if (!tbConf.getSubTables().isEmpty()) {
List<Table> subTables = new ArrayList<Table>();
for (TableConf tc : tbConf.getSubTables()) {
Table tb = getTable(tc, module, con);
tb.setParentProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(tc.getParentField()));
tb.setRefType(tc.getRefType());
subTables.add(tb);
}
table.setSubTables(subTables);
}
return table;
}
use of com.free.framework.code.tools.model.Table in project free-framework by a601942905git.
the class SqlServerTableService method getTable.
/**
* 获取指定表信息并封装成Table对象
* @param tbConf
* @param module
* @param con
*/
public Table getTable(TableConf tbConf, Module module, Connection con) throws SQLException {
String tableName = tbConf.getName();
Table table = new Table();
table.setTableFullName(tableName);
table.setTableName(tableName);
if (module.isDeleteTablePrefix() && !CodeUtil.isEmpty(tbConf.getPrefix())) {
table.setTableName(tableName.toLowerCase().replaceFirst(tbConf.getPrefix(), ""));
}
System.out.println(tbConf);
// 获取表各字段的信息
getTableColumns(table, con);
table.setPrimaryKey(getTablePrimaryKey(tableName, con));
table.setPrimaryProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(table.getPrimaryKey()));
table.setRemark(getTableRemark(tableName, con));
table.setPrimaryKeyType(getColumnType(table, table.getPrimaryKey()));
table.setPrimaryPropertyType(CodeUtil.convertType(table.getPrimaryKeyType()));
table.setPrimaryCamelProperty(CodeUtil.convertToCamelCase(table.getPrimaryKey()));
table.setEntityCamelName(CodeUtil.isEmpty(tbConf.getEntityName()) ? CodeUtil.convertToCamelCase(table.getTableName()) : tbConf.getEntityName());
table.setEntityName(CodeUtil.convertToFirstLetterLowerCaseCamelCase(table.getTableName()));
table.setModule(module);
// 设置子表的entity属性
if (!tbConf.getSubTables().isEmpty()) {
List<Table> subTables = new ArrayList<Table>();
for (TableConf tc : tbConf.getSubTables()) {
Table tb = getTable(tc, module, con);
tb.setParentProperty(CodeUtil.convertToFirstLetterLowerCaseCamelCase(tc.getParentField()));
tb.setRefType(tc.getRefType());
subTables.add(tb);
}
table.setSubTables(subTables);
}
return table;
}
Aggregations