Skip to content

Commit eb0e628

Browse files
author
nguyen
committed
Clone from qwazer and use code from yorukoglu
Ref. qwazer#46
1 parent cc33d5c commit eb0e628

23 files changed

+1851
-1612
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ dependency-reduced-pom.xml
1010
buildNumber.properties
1111
output
1212
scheme2ddl.iml
13+
/.settings/
14+
/src/test/
15+
/src/test/resources/

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,33 @@ More command line options
3939
java -jar scheme2ddl.jar -help
4040
...
4141
Options:
42-
-help, -h print this message
43-
-url, DB connection URL
44-
example: scott/tiger@localhost:1521:ORCL
45-
-o, --output, output dir
46-
-p, --parallel, number of parallel thread (default 4)
47-
-s, --schemas, a comma separated list of schemas for processing
48-
(works only if connected to oracle as sysdba)
49-
-c, --config, path to scheme2ddl config file (xml)
50-
-f, --filter, filter for specific DDL objects
51-
every LIKE wildcard can be used
52-
-tf, --type-filter, filter for specific DDL object types
53-
-tfm, --type-filtermode, mode for type filter: include(default) or exclude
54-
--stop-on-warning, stop on getting DDL error (skip by default)
55-
-rsv, replace actual sequence values with 1
56-
--replace-sequence-values,
57-
-tc,--test-connection, test db connection available
58-
-version, print version info and exit
42+
-help, -h print this message
43+
-url, DB connection URL
44+
example: scott/tiger@localhost:1521:ORCL
45+
-o, --output, output dir
46+
-oe, --out-encoding, out file encoding
47+
example: UTF-8
48+
-p, --parallel, number of parallel thread (default 4)
49+
-s, --schemas, a comma separated list of schemas for processing
50+
(works only if connected to oracle as sysdba)
51+
-c, --config, path to scheme2ddl config file (xml)
52+
-f, --filter, filter for specific DDL objects
53+
every LIKE wildcard can be used
54+
-tf, --type-filter, filter for specific DDL object types
55+
-tfm, --type-filtermode, mode for type filter: include(default) or exclude
56+
-dta, --ddl-time-after, export objects with last DDL time after the time specified
57+
example: 2016-11-27 : exports objects that modified after 27 Nov 2016
58+
example: "2016-11-27 01:00:00" : exports objects that modified after 27 Nov 2016, 1am
59+
-dtb, --ddl-time-before, export objects with last DDL time before the time specified
60+
example: "2016-11-27 01:00:00"
61+
-dti, --ddl-time-in, export objects with last DDL time in last n[minute|hour|day]
62+
example: "6 hour" : exports objects that modified in last 6 hours
63+
example: 2d : exports objects that modified in last 2 days
64+
--stop-on-warning, stop on getting DDL error (skip by default)
65+
-rsv, replace actual sequence values with 1
66+
--replace-sequence-values,
67+
-tc,--test-connection, test db connection available
68+
-version, print version info and exit
5969

6070
On Unix platform you can run `scheme2ddl.jar` as executable file:
6171

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@
182182
<scope>test</scope>
183183
</dependency>
184184

185+
<dependency>
186+
<groupId>org.springframework.boot</groupId>
187+
<artifactId>spring-boot-devtools</artifactId>
188+
</dependency>
185189
</dependencies>
186190

187191

src/main/java/com/googlecode/scheme2ddl/DDLFormatter.java

Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,91 +12,93 @@
1212
*/
1313
public class DDLFormatter {
1414

15-
private boolean noFormat;
16-
private boolean sortCreateIndexStatements = true;
17-
private boolean statementOnNewLine;
18-
private boolean isMorePrettyFormat = false;
15+
private boolean noFormat;
16+
private boolean sortCreateIndexStatements = true;
17+
private boolean statementOnNewLine;
18+
private boolean isMorePrettyFormat = false;
1919

20-
static String newline = "\r\n"; //may be use "\n"
20+
static String newline = "\r\n"; // may be use "\n"
2121

22-
public String formatDDL(String ddl) {
23-
if (noFormat)
24-
return ddl;
22+
public String formatDDL(String ddl) {
23+
if (noFormat)
24+
return ddl;
25+
26+
ddl = ddl.trim() + "\n";
2527

26-
ddl = ddl.trim() + "\n";
27-
2828
// replace unix line endings with windows
2929
ddl = ddl.replaceAll("\r\n", "\n");
30-
ddl = ddl.replaceAll("\n", "\r\n");
31-
32-
if (!isMorePrettyFormat)
33-
return ddl;
34-
35-
/* smart formatting */
36-
ddl = ddl.replaceAll(newline + "GRANT ", newline + newline + " GRANT ");
37-
ddl = ddl.replaceAll(newline + "COMMENT ", newline + newline + " COMMENT ");
38-
ddl = ddl.replaceAll(newline + " CREATE ", newline + "CREATE ");
39-
ddl = ddl.replaceAll(newline + " ALTER ", newline + "ALTER ");
40-
return ddl;
41-
}
42-
43-
public void setNoFormat(Boolean noFormat) {
44-
this.noFormat = noFormat;
45-
}
46-
47-
@Deprecated
48-
public void setStatementOnNewLine(Boolean statementOnNewLine) {
49-
this.statementOnNewLine = statementOnNewLine;
50-
}
51-
52-
public void setIsMorePrettyFormat(boolean isMorePrettyFormat) {
53-
this.isMorePrettyFormat = isMorePrettyFormat;
54-
}
55-
56-
public void setSortCreateIndexStatements(boolean sortCreateIndexStatements) {
57-
this.sortCreateIndexStatements = sortCreateIndexStatements;
58-
}
59-
60-
public String replaceActualSequenceValueWithOne(String res) {
61-
62-
String output;
63-
Pattern p = Pattern.compile("CREATE SEQUENCE (.*) START WITH (\\d+) (.*)");
64-
Matcher m = p.matcher(res);
65-
if (m.find()) {
66-
output = m.replaceFirst("CREATE SEQUENCE " + m.group(1) + " START WITH 1 " + m.group(3) );
67-
if (!"1".equals(m.group(2)))
68-
output = output + newline + "/* -- actual sequence value was replaced by scheme2ddl to 1 */";
69-
}
70-
else {
71-
output = res;
72-
}
73-
return output;
74-
}
75-
76-
/**
77-
* Read input string with list of 'create index' statements and, tokenize and sort alphabetically.
78-
* @param dependentDLL -string with list of 'create index' statements
79-
* @return string with sorted alphabetically 'create index' statements
80-
*/
81-
public String sortIndexesInDDL(String dependentDLL) {
82-
if (noFormat || !sortCreateIndexStatements){
83-
return dependentDLL;
84-
}
85-
String[] parts = dependentDLL.split("(?=CREATE INDEX)|(?=CREATE UNIQUE INDEX)|(?=CREATE BITMAP INDEX)");
86-
List<String> list = new ArrayList<String>();
87-
for (String part : parts) {
88-
if (part != null && !part.trim().isEmpty()) {
89-
list.add(part.trim());
90-
}
91-
}
92-
Collections.sort(list);
93-
StringBuilder s = new StringBuilder();
94-
String prefix = "\n "; //to preserve formatting of dbms_metadata.get_depended_ddl output
95-
for (String statement:list){
96-
s.append(prefix);
97-
prefix = "\n";
98-
s.append(statement);
99-
}
100-
return s.toString();
101-
}
30+
ddl = ddl.replaceAll("\n", "\r\n");
31+
32+
if (!isMorePrettyFormat)
33+
return ddl;
34+
35+
/* smart formatting */
36+
ddl = ddl.replaceAll(newline + "GRANT ", newline + newline + " GRANT ");
37+
ddl = ddl.replaceAll(newline + "COMMENT ", newline + newline + " COMMENT ");
38+
ddl = ddl.replaceAll(newline + " CREATE ", newline + "CREATE ");
39+
ddl = ddl.replaceAll(newline + " ALTER ", newline + "ALTER ");
40+
return ddl;
41+
}
42+
43+
public void setNoFormat(Boolean noFormat) {
44+
this.noFormat = noFormat;
45+
}
46+
47+
@Deprecated
48+
public void setStatementOnNewLine(Boolean statementOnNewLine) {
49+
this.statementOnNewLine = statementOnNewLine;
50+
}
51+
52+
public void setIsMorePrettyFormat(boolean isMorePrettyFormat) {
53+
this.isMorePrettyFormat = isMorePrettyFormat;
54+
}
55+
56+
public void setSortCreateIndexStatements(boolean sortCreateIndexStatements) {
57+
this.sortCreateIndexStatements = sortCreateIndexStatements;
58+
}
59+
60+
public String replaceActualSequenceValueWithOne(String res) {
61+
62+
String output;
63+
Pattern p = Pattern.compile("CREATE SEQUENCE (.*) START WITH (\\d+) (.*)");
64+
Matcher m = p.matcher(res);
65+
if (m.find()) {
66+
output = m.replaceFirst("CREATE SEQUENCE " + m.group(1) + " START WITH 1 " + m.group(3));
67+
if (!"1".equals(m.group(2)))
68+
output = output + newline + "/* -- actual sequence value was replaced by scheme2ddl to 1 */";
69+
} else {
70+
output = res;
71+
}
72+
return output;
73+
}
74+
75+
/**
76+
* Read input string with list of 'create index' statements and, tokenize and
77+
* sort alphabetically.
78+
*
79+
* @param dependentDLL
80+
* -string with list of 'create index' statements
81+
* @return string with sorted alphabetically 'create index' statements
82+
*/
83+
public String sortIndexesInDDL(String dependentDLL) {
84+
if (noFormat || !sortCreateIndexStatements) {
85+
return dependentDLL;
86+
}
87+
String[] parts = dependentDLL.split("(?=CREATE INDEX)|(?=CREATE UNIQUE INDEX)|(?=CREATE BITMAP INDEX)");
88+
List<String> list = new ArrayList<String>();
89+
for (String part : parts) {
90+
if (part != null && !part.trim().isEmpty()) {
91+
list.add(part.trim());
92+
}
93+
}
94+
Collections.sort(list);
95+
StringBuilder s = new StringBuilder();
96+
String prefix = "\n "; // to preserve formatting of dbms_metadata.get_depended_ddl output
97+
for (String statement : list) {
98+
s.append(prefix);
99+
prefix = "\n";
100+
s.append(statement);
101+
}
102+
return s.toString();
103+
}
102104
}

0 commit comments

Comments
 (0)