top.lingkang.finalsql.ui.GenerateBuildSqlite3 Maven / Gradle / Ivy
The newest version!
package top.lingkang.finalsql.ui;
import top.lingkang.finalsql.sql.FinalSql;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author lingkang
* Created by 2022/11/8
*/
public class GenerateBuildSqlite3 implements GenerateBuild {
// 获取所有表
private final String sql_tables = "SELECT name FROM sqlite_master WHERE type ='table';";
private final String sql_column = "Pragma Table_Info(%s)";
@Override
public void build(FinalSql finalSql, GenerateProperties properties) {
GenerateUtils.checkGenerateProperties(properties);
List tables = finalSql.selectForList(sql_tables, String.class);
if (tables.isEmpty())
return;
String pageName = GenerateUtils.getPage(properties.getOutDir());
String template = GenerateUtils.readFile(
GenerateBuildSqlite3.class.getClassLoader().getResourceAsStream("java-template.txt")
);
if (!GenerateUtils.isBlank(pageName)) {
pageName = "package " + pageName + ";";
}
template = template.replace("#package", pageName);
String ignoreTablePrefix = properties.getIgnoreTablePrefix();
HashSet hasClassName = new HashSet<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
for (String table : tables) {
String className = GenerateUtils.handlerTableName(table, ignoreTablePrefix);
if (hasClassName.contains(className)) {// 防止相同类型名冲突
className = GenerateUtils.hasSomeName(className, hasClassName);
}
hasClassName.add(className);
String t = template;
t = t.replace("#date", date);
t = t.replace("#table", table);
t = t.replace("#className", className);
HashSet impl = new HashSet<>();
// 列
List