Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
306f56c8
Commit
306f56c8
authored
Sep 12, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] gen gernerator xml impl
parent
218e750c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
66 deletions
+121
-66
GenGeneratorXml.java
atms-gen/src/test/java/com/neo/GenGeneratorXml.java
+121
-66
No files found.
atms-gen/src/test/java/com/neo/GenGeneratorXml.java
View file @
306f56c8
...
...
@@ -6,6 +6,7 @@ import java.io.BufferedReader;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
...
...
@@ -19,76 +20,69 @@ public class GenGeneratorXml {
public
static
final
boolean
IS_ADMIN
=
true
;
public
static
final
boolean
IS_VAT
=
false
;
public
static
final
String
LINE_SPLITER
=
"\r\n"
;
public
static
final
String
ORACLE
=
"oracle"
;
public
static
final
String
MYSQL
=
"mysql"
;
public
static
void
main
(
String
[]
args
)
throws
URISyntaxException
,
ClassNotFoundException
,
IOException
{
copyWithReplaceName
(
getAdminEntityPath
(),
getAdminTmpFile
(),
IS_ADMIN
);
System
.
out
.
println
(
"copy admin entity over ,and begin copy project path"
);
copyWithReplaceName
(
getProjectEntityPath
(),
getVatTmpFile
(),
IS_VAT
);
genConfigXml
(
getAdminEntityPath
(),
getAdminTmpFile
(),
IS_ADMIN
,
ORACLE
);
genConfigXml
(
getProjectEntityPath
(),
getVatTmpFile
(),
IS_VAT
,
ORACLE
);
}
/**
* <table tableName="FormulaParamOption" domainObjectName="FormulaParamOption">
* <property name="useActualColumnNames" value="true"/>
* <property name="ignoreQualifiersAtRuntime" value="true"/>
* <columnOverride column="Value" javaType="java.lang.String" jdbcType="VARCHAR"/>
* <columnOverride column="Name" javaType="java.lang.String" jdbcType="VARCHAR"/>
* <columnOverride column="ShortName" javaType="java.lang.String" jdbcType="VARCHAR"/>
* </table>
*
* @param source
* @param tempObj
* @param isAdmin
*/
public
static
void
copyWithReplaceName
(
String
source
,
String
tempObj
,
final
boolean
isAdmin
)
{
public
static
void
genConfigXml
(
String
source
,
String
tempObj
,
final
boolean
isAdmin
,
String
dbType
)
{
File
tempFile
=
new
File
(
tempObj
);
if
(!
tempFile
.
exists
())
tempFile
.
mkdirs
();
File
toFile
=
new
File
(
tempObj
+
((
isAdmin
)
?
"generatorConfig.xml"
:
"vatGeneratorConfig.xml"
));
if
(
toFile
.
exists
())
toFile
.
delete
();
try
{
toFile
.
createNewFile
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
List
<
File
>
entities
=
Arrays
.
asList
(
new
File
(
source
).
listFiles
());
entities
.
forEach
(
m
->
{
File
toFile
=
new
File
(
tempObj
+
m
.
getName
());
if
(
toFile
.
exists
())
toFile
.
delete
();
try
{
toFile
.
createNewFile
();
System
.
out
.
println
(
"cp from "
+
m
.
getAbsolutePath
()
+
" to "
+
toFile
.
getAbsolutePath
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
(
BufferedReader
burReader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
m
)));
BufferedWriter
bufWrite
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
toFile
))))
{
String
line
=
null
;
String
columLine
=
null
;
Table
table
=
new
Table
();
while
((
line
=
burReader
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"@Table"
))
{
System
.
out
.
println
(
"table line:"
+
line
);
table
.
tableName
=
extractName
(
line
);
}
else
if
(
line
.
contains
(
"class"
))
{
if
(
line
.
contains
(
"IdClass"
)||
line
.
contains
(
"classCode"
))
continue
;
System
.
out
.
println
(
"entity line:"
+
line
);
table
.
entityName
=
extractEntityName
(
line
);
}
else
if
(
line
.
contains
(
"@Column"
))
{
if
(!
line
.
contains
(
"@ColumnDefault"
))
columLine
=
line
;
}
else
if
(
line
.
contains
(
"public"
))
{
if
(
line
.
contains
(
"class"
)
||
line
.
contains
(
"void"
)
||
line
.
contains
(
"hashCode"
)
||
line
.
contains
(
"equals"
)
||
line
.
contains
(
"Date"
)
||
line
.
contains
(
"String"
))
{
continue
;
}
else
{
System
.
out
.
println
(
"column:"
+
columLine
);
System
.
out
.
println
(
"method:"
+
line
);
table
.
columnOverrides
.
add
(
new
ColumnOverride
(
extractName
(
columLine
),
extractJavaTypeName
(
line
),
""
));
try
(
BufferedWriter
bufWrite
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
toFile
))))
{
bufWrite
.
write
(
getHead
(
dbType
,
isAdmin
));
entities
.
forEach
(
m
->
{
try
(
BufferedReader
burReader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
m
)));)
{
String
line
=
null
;
String
columLine
=
null
;
Table
table
=
new
Table
();
while
((
line
=
burReader
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"@Table"
))
{
System
.
out
.
println
(
"table line:"
+
line
);
table
.
tableName
=
extractName
(
line
);
}
else
if
(
line
.
contains
(
"class"
))
{
if
(
line
.
contains
(
"IdClass"
)
||
line
.
contains
(
"classCode"
))
continue
;
System
.
out
.
println
(
"entity line:"
+
line
);
table
.
entityName
=
extractEntityName
(
line
);
}
else
if
(
line
.
contains
(
"@Column"
))
{
if
(!
line
.
contains
(
"@ColumnDefault"
))
columLine
=
line
;
}
else
if
(
line
.
contains
(
"public"
))
{
if
(
line
.
contains
(
"class"
)
||
line
.
contains
(
"void"
)
||
line
.
contains
(
"hashCode"
)
||
line
.
contains
(
"equals"
)
||
line
.
contains
(
"Date"
)
||
line
.
contains
(
"String"
))
{
continue
;
}
else
{
System
.
out
.
println
(
"column:"
+
columLine
);
System
.
out
.
println
(
"method:"
+
line
);
table
.
columnOverrides
.
add
(
new
ColumnOverride
(
extractName
(
columLine
),
extractJavaTypeName
(
line
),
""
));
}
}
}
// bufWrite.write(line + "\r\n");
bufWrite
.
write
(
table
.
toString
());
bufWrite
.
write
(
"\r\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"xml:"
+
table
.
toString
());
bufWrite
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
});
});
bufWrite
.
write
(
getEnd
());
bufWrite
.
flush
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
static
class
Table
{
...
...
@@ -98,11 +92,11 @@ public class GenGeneratorXml {
@Override
public
String
toString
()
{
return
"<table tableName=\""
+
tableName
+
"\" domainObjectName=\""
+
entityName
+
"\">"
+
LINE_SPLITER
+
"<property name=\"useActualColumnNames\" value=\"false\"/>"
+
LINE_SPLITER
+
"<property name=\"ignoreQualifiersAtRuntime\" value=\"true\"/>"
+
LINE_SPLITER
+
return
"
<table tableName=\""
+
tableName
+
"\" domainObjectName=\""
+
entityName
+
"\">"
+
LINE_SPLITER
+
"
<property name=\"useActualColumnNames\" value=\"false\"/>"
+
LINE_SPLITER
+
"
<property name=\"ignoreQualifiersAtRuntime\" value=\"true\"/>"
+
LINE_SPLITER
+
getColumnsString
()
+
"</table>"
+
LINE_SPLITER
;
"
</table>"
+
LINE_SPLITER
;
}
public
String
getColumnsString
()
{
...
...
@@ -121,10 +115,22 @@ public class GenGeneratorXml {
@Override
public
String
toString
()
{
return
"<columnOverride column=\""
+
column
+
"\" javaType=\""
+
getJavaType
(
javaType
)
+
"\" jdbcType=\""
+
getJdbcType
(
jdbcType
)
+
"\"/>"
+
LINE_SPLITER
;
return
" <columnOverride column=\""
+
column
+
"\" javaType=\""
+
getJavaType
(
javaType
)
+
"\" "
+
// "jdbcType=\"" + getJdbcType(jdbcType) + "\""
"/>"
+
LINE_SPLITER
;
}
public
String
getJavaType
(
String
javaType
)
{
switch
(
javaType
)
{
case
"Integer"
:
return
"java.lang.Integer"
;
case
"Boolean"
:
return
"java.lang.Boolean"
;
case
"Long"
:
return
"java.lang.Long"
;
case
"BigDecimal"
:
return
"java.math.BigDecimal"
;
}
return
javaType
;
}
...
...
@@ -170,7 +176,7 @@ public class GenGeneratorXml {
String
tempFilePath
=
""
;
String
basePath
=
file
.
getPath
().
split
(
"target"
)[
0
];
tempFilePath
=
basePath
+
"gen"
+
File
.
separator
+
"
admin
"
+
File
.
separator
;
+
File
.
separator
+
"
config
"
+
File
.
separator
;
return
tempFilePath
;
}
...
...
@@ -180,7 +186,7 @@ public class GenGeneratorXml {
String
tempFilePath
=
""
;
String
basePath
=
file
.
getPath
().
split
(
"target"
)[
0
];
tempFilePath
=
basePath
+
"gen"
+
File
.
separator
+
"
vat
"
+
File
.
separator
;
+
File
.
separator
+
"
config
"
+
File
.
separator
;
return
tempFilePath
;
}
...
...
@@ -203,4 +209,53 @@ public class GenGeneratorXml {
int
endIndex
=
line
.
indexOf
(
"get"
,
beginIndex
+
6
);
return
line
.
substring
(
beginIndex
+
6
,
endIndex
).
trim
();
}
private
static
String
getHead
(
String
dbType
,
Boolean
isAdmin
)
{
return
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
"<!DOCTYPE generatorConfiguration\n"
+
" PUBLIC \"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN\"\n"
+
" \"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd\">\n"
+
"<generatorConfiguration>\n"
+
" <properties resource=\""
+(
isAdmin
?
"generator"
:
"vatGenerator"
)+
".properties\" />\n"
+
" <context id=\"contextId\" targetRuntime=\"MyBatis3\">\n"
+
" <property name=\"autoDelimitKeywords\" value=\"true\" />\n"
+
" <property name=\"beginningDelimiter\" value=\""
+
(
dbType
.
equals
(
ORACLE
)
?
"""
:
"`"
)
+
"\"/>\n"
+
" <property name=\"endingDelimiter\" value=\""
+
(
dbType
.
equals
(
ORACLE
)
?
"""
:
"`"
)
+
"\"/>\n"
+
" <property name=\"javaFileEncoding\" value=\"UTF-8\" />\n"
+
" <!--<plugin type=\"cn.pwc.demo.util.MapperAnnotationPlugin\" />-->\n"
+
" <plugin type=\"org.mybatis.generator.plugins.MapperAnnotationPlugin\"/>\n"
+
" <plugin type=\"org.mybatis.generator.plugins.RowBoundsPlugin\" />\n"
+
" <plugin type=\"org.mybatis.generator.plugins.ToStringPlugin\" />\n"
+
" <plugin type=\"org.mybatis.generator.plugins.SerializablePlugin\" />\n"
+
" <commentGenerator>\n"
+
" <property name=\"suppressDate\" value=\"true\" />\n"
+
" <property name=\"addRemarkComments\" value=\"true\" />\n"
+
" </commentGenerator>\n"
+
"\n"
+
" <jdbcConnection driverClass=\"${jdbc.driverClass}\" connectionURL=\"${jdbc.connectionURL}\" userId=\"${jdbc.userId}\"\n"
+
" password=\"${jdbc.password}\">\n"
+
" <property name=\"remarksReporting\" value=\"true\"></property>\n"
+
" </jdbcConnection>\n"
+
"\n"
+
" <javaTypeResolver>\n"
+
" <property name=\"forceBigDecimals\" value=\"false\" />\n"
+
" </javaTypeResolver>\n"
+
"\n"
+
" <javaModelGenerator targetPackage=\"pwc.taxtech.atms"
+
(
isAdmin
?
"."
:
".vat."
)
+
"entity\" targetProject=\"../../src/main/java\">\n"
+
" <property name=\"trimStrings\" value=\"true\"/>\n"
+
" "
+
(
isAdmin
?
"<property name=\"rootClass\" value=\"pwc.taxtech.atms.entitiy.BaseEntity\"/>"
:
""
)
+
"\n"
+
" </javaModelGenerator>\n"
+
"\n"
+
" <sqlMapGenerator targetPackage=\"pwc.taxtech.atms"
+
(
isAdmin
?
"."
:
".vat."
)
+
"dao\" targetProject=\"../../src/main/resources\">\n"
+
" </sqlMapGenerator>\n"
+
"\n"
+
" <javaClientGenerator type=\"XMLMAPPER\" targetPackage=\"pwc.taxtech.atms"
+
(
isAdmin
?
"."
:
".vat."
)
+
"dao\" targetProject=\"../../src/main/java\">\n"
+
" <property name=\"rootInterface\" value=\"pwc.taxtech.atms."
+
(
isAdmin
?
"MyMapper"
:
"MyVatMapper"
)
+
"\"/>\n"
+
" </javaClientGenerator>\n"
;
}
private
static
String
getEnd
()
{
return
" </context>\n"
+
"</generatorConfiguration>"
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment