@@ -24,7 +24,8 @@ public class TableParseUtil {
2424 * @param tableSql
2525 * @return
2626 */
27- public static ClassInfo processTableIntoClassInfo (String tableSql , boolean isUnderLineToCamelCase ) throws IOException {
27+ public static ClassInfo processTableIntoClassInfo (String tableSql , boolean isUnderLineToCamelCase ,String tinyintTransType )
28+ throws IOException {
2829 if (tableSql ==null || tableSql .trim ().length ()==0 ) {
2930 throw new CodeGenerateException ("Table structure can not be empty." );
3031 }
@@ -41,7 +42,9 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
4142 }
4243
4344 //新增处理create table if not exists members情况
44- if (tableName .contains ("if not exists" )) tableName =tableName .replaceAll ("if not exists" ,"" );
45+ if (tableName .contains ("if not exists" )) {
46+ tableName =tableName .replaceAll ("if not exists" ,"" );
47+ }
4548
4649 if (tableName .contains ("`" )) {
4750 tableName = tableName .substring (tableName .indexOf ("`" )+1 , tableName .lastIndexOf ("`" ));
@@ -101,20 +104,22 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
101104 String fieldListTmp = tableSql .substring (tableSql .indexOf ("(" )+1 , tableSql .lastIndexOf (")" ));
102105
103106 // 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
104- Matcher matcher = Pattern .compile ("comment `(.*?)\\ `" ).matcher (fieldListTmp ); // "\\{(.*?)\\}"
105- while (matcher .find ()){
107+ String commentPattenStr1 ="comment `(.*?)\\ `" ;
108+ Matcher matcher1 = Pattern .compile (commentPattenStr1 ).matcher (fieldListTmp );
109+ while (matcher1 .find ()){
106110
107- String commentTmp = matcher .group ();
111+ String commentTmp = matcher1 .group ();
108112 //2018-9-27 zhengk 不替换,只处理,支持COMMENT评论里面多种注释
109113 //commentTmp = commentTmp.replaceAll("\\ comment `|\\`", " "); // "\\{|\\}"
110114
111115 if (commentTmp .contains ("," )) {
112116 String commentTmpFinal = commentTmp .replaceAll ("," , "," );
113- fieldListTmp = fieldListTmp .replace (matcher .group (), commentTmpFinal );
117+ fieldListTmp = fieldListTmp .replace (matcher1 .group (), commentTmpFinal );
114118 }
115119 }
116120 //2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
117- Matcher matcher2 = Pattern .compile ("\\ `(.*?)\\ `" ).matcher (fieldListTmp ); // "\\{(.*?)\\}"
121+ String commentPattenStr2 ="\\ `(.*?)\\ `" ;
122+ Matcher matcher2 = Pattern .compile (commentPattenStr2 ).matcher (fieldListTmp );
118123 while (matcher2 .find ()){
119124 String commentTmp2 = matcher2 .group ();
120125 if (commentTmp2 .contains ("," )) {
@@ -123,7 +128,8 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
123128 }
124129 }
125130 //2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
126- Matcher matcher3 = Pattern .compile ("\\ ((.*?)\\ )" ).matcher (fieldListTmp ); // "\\{(.*?)\\}"
131+ String commentPattenStr3 ="\\ ((.*?)\\ )" ;
132+ Matcher matcher3 = Pattern .compile (commentPattenStr3 ).matcher (fieldListTmp );
127133 while (matcher3 .find ()){
128134 String commentTmp3 = matcher3 .group ();
129135 if (commentTmp3 .contains ("," )) {
@@ -148,7 +154,6 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
148154 &&!columnLine .contains ("pctincrease" )
149155 &&!columnLine .contains ("buffer_pool" )&&!columnLine .contains ("tablespace" )
150156 &&!(columnLine .contains ("primary" )&&i >3 ));
151-
152157 if (specialFlag ){
153158 //如果是oracle的number(x,x),可能出现最后分割残留的,x),这里做排除处理
154159 if (columnLine .length ()<5 ) {continue ;}
@@ -157,9 +162,8 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
157162 columnLine =columnLine .replaceAll ("`" ," " ).replaceAll ("\" " ," " ).replaceAll ("'" ,"" ).replaceAll (" " ," " ).trim ();
158163 //如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前
159164 columnName = columnLine .substring (0 , columnLine .indexOf (" " ));
160-
161165 // field Name
162- // 2019-09-08 yj 添加是否下划线转换为驼峰的判断
166+ // 2019-09-08 yj 添加是否下划线转换为驼峰的判断
163167 String fieldName ;
164168 if (isUnderLineToCamelCase ){
165169 fieldName = StringUtils .lowerCaseFirst (StringUtils .underlineToCamelCase (columnName ));
@@ -184,7 +188,7 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
184188 fieldClass = Float .class .getSimpleName ();
185189 } else if (columnLine .contains ("double" )) {
186190 fieldClass = Double .class .getSimpleName ();
187- } else if (columnLine .contains ("datetime" ) || columnLine .contains ("timestamp" )) {
191+ } else if (columnLine .contains ("time" ) || columnLine . contains ( "date" ) || columnLine . contains ( " datetime" ) || columnLine .contains ("timestamp" )) {
188192 fieldClass = Date .class .getSimpleName ();
189193 } else if (columnLine .contains ("varchar" ) || columnLine .contains (" text" )|| columnLine .contains ("char" )
190194 || columnLine .contains ("clob" )||columnLine .contains ("blob" )||columnLine .contains ("json" )) {
@@ -221,9 +225,12 @@ public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnd
221225 }else {
222226 fieldClass = BigDecimal .class .getSimpleName ();
223227 }
224- } else if (columnLine .contains ("boolean" )|| columnLine . contains ( "tinyint" ) ) {
228+ } else if (columnLine .contains ("boolean" )) {
225229 //20190910 MOSHOW.K.ZHENG 新增对boolean的处理(感谢@violinxsc的反馈)以及修复tinyint类型字段无法生成boolean类型问题(感谢@hahaYhui的反馈)
226230 fieldClass = Boolean .class .getSimpleName ();
231+ } else if (columnLine .contains ("tinyint" ) ) {
232+ //20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
233+ fieldClass =tinyintTransType ;
227234 } else {
228235 fieldClass = String .class .getSimpleName ();
229236 }
0 commit comments