Commit 3caaa7dd authored by Quxl's avatar Quxl

优化

parent 04f796bb
......@@ -59,8 +59,6 @@ public class MysqlTo {
public void execute(String name, String comment) {
try {
boolean f_date = false;
boolean f_numeric = false;
String sql = "SELECT C.COLUMN_NAME, C.COLUMN_TYPE, C.COLUMN_COMMENT, CU.CONSTRAINT_NAME FROM COLUMNS C LEFT JOIN KEY_COLUMN_USAGE CU ON CU.TABLE_SCHEMA = C.TABLE_SCHEMA AND CU.TABLE_NAME = C.TABLE_NAME AND CU.COLUMN_NAME = C.COLUMN_NAME WHERE C.TABLE_SCHEMA = '" + db_name + "' AND C.TABLE_NAME = '" + name + "'";
System.out.println(sql);
ResultSet set = conn.prepareStatement(sql).executeQuery();
......@@ -79,14 +77,8 @@ public class MysqlTo {
if("PRIMARY".equals(constraintName)) {
paramyKeys.add(columnName);
}
if (columnType.equalsIgnoreCase("datetime") || columnType.equalsIgnoreCase("date")) {
f_date = true;
}
if (columnType.equalsIgnoreCase("decimal") || columnType.equalsIgnoreCase("numeric")) {
f_numeric = true;
}
}
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments, f_date, f_numeric);
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments);
} catch (Exception e) {
throw new RuntimeException(e);
}
......
......@@ -31,19 +31,23 @@ public class ReverseUtil {
* @return
* @throws IOException
*/
public static void parseEntity(String pkg_name, String author, String root, String name, String comment, List<String> paramyKeys, List<String> columnNames, List<String> colTypes, List<String> colComments, boolean f_date, boolean f_numeric) throws IOException {
public static void parseEntity(String pkg_name, String author, String root, String name, String comment, List<String> paramyKeys, List<String> columnNames, List<String> colTypes, List<String> colComments) throws IOException {
StringBuffer sb = new StringBuffer();
sb.append("package " + pkg_name + ";" + "\n\n");
sb.append("import javax.persistence.Entity;" + "\n\n");
if(paramyKeys.size() > 0) {
sb.append("import javax.persistence.Id;" + "\n\n");
}
if (f_date) {
for(String columnType : colTypes) {
if (columnType.equalsIgnoreCase("datetime") || columnType.equalsIgnoreCase("date")) {
sb.append("import java.util.Date;" + "\n\n");
}
if(f_numeric) {
break;
} else if (columnType.equalsIgnoreCase("decimal") || columnType.equalsIgnoreCase("numeric")) {
sb.append("import java.math.BigDecimal;" + "\n\n");
break;
}
}
sb.append("/**" + "\n");
sb.append(" * @author " + author + "\n");
sb.append(" * @since " + DateUtil.format(new Date(), DateUtil.FMT_DATE) + "\n");
......
......@@ -72,8 +72,6 @@ public class SqlServerTo {
public void execute(String name, String comment) {
try {
boolean f_date = false;
boolean f_numeric = false;
ResultSet set = conn.prepareStatement("SELECT COL.NAME AS COLUMN_NAME, T.NAME AS COLUMN_TYPE, CAST(P.VALUE AS VARCHAR(999)) AS COLUMN_COMMENT, CASE WHEN EXISTS (SELECT 1 FROM dbo.sysindexes SI INNER JOIN dbo.sysindexkeys SIK ON SI.ID = SIK.ID AND SI.INDID = SIK.INDID INNER JOIN dbo.syscolumns SC ON SC.ID = SIK.ID AND SC.COLID = SIK.COLID INNER JOIN dbo.sysobjects SO ON SO.NAME = SI.NAME AND SO.XTYPE = 'PK' WHERE SC.ID = COL.ID AND SC.COLID = COL.COLID ) THEN 1 ELSE 0 END AS IS_PARAMY_KEY FROM syscolumns AS COL LEFT JOIN systypes T ON T.XUSERTYPE = COL.XTYPE LEFT JOIN sys.extended_properties P ON COL.ID = P.MAJOR_ID AND COL.COLID = P.MAJOR_ID WHERE COL.ID=OBJECT_ID('" + name + "')").executeQuery();
List<String> names = new ArrayList<String>();
List<String> types = new ArrayList<String>();
......@@ -90,15 +88,9 @@ public class SqlServerTo {
if(isParamyKey == 1) {
paramyKeys.add(columnName);
}
if (columnType.equalsIgnoreCase("datetime") || columnType.equalsIgnoreCase("date")) {
f_date = true;
}
if (columnType.equalsIgnoreCase("decimal") || columnType.equalsIgnoreCase("numeric")) {
f_numeric = true;
}
}
if(!name.startsWith("sys") && !name.startsWith("SYS")) {
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments, f_date, f_numeric);
ReverseUtil.parseEntity(pkg_name, author, root, name, comment, paramyKeys, names, types, comments);
}
} catch (Exception e) {
throw new RuntimeException(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment