/
DbExportCommand.java
103 lines (86 loc) · 3.68 KB
/
DbExportCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.jumpmind.symmetric.DbExport.Compatible;
import org.jumpmind.symmetric.DbExport.Format;
/**
* Export the structure and data from database tables to file.
*/
public class DbExportCommand extends AbstractCommandLauncher {
private static final String OPTION_FORMAT = "format";
private static final String OPTION_COMPATIBLE = "compatible";
private static final String OPTION_ADD_DROP_TABLE = "add-drop-table";
private static final String OPTION_NO_CREATE_INFO = "no-create-info";
private static final String OPTION_NO_DATA = "no-data";
private static final String OPTION_COMMENTS = "comments";
public DbExportCommand() {
super("dbexport", "DbExport.Option.");
}
public static void main(String[] args) {
new DbExportCommand().execute(args);
}
protected void printHelp(Options options) {
System.out.println(commandName + " version " + Version.version());
System.out.println("Export the structure and data from database tables to file.\n");
super.printHelp(options);
}
@Override
protected void buildOptions(Options options) {
super.buildOptions(options);
addOption(options, null, OPTION_FORMAT, true);
addOption(options, null, OPTION_COMPATIBLE, true);
addOption(options, null, OPTION_ADD_DROP_TABLE, false);
addOption(options, null, OPTION_NO_CREATE_INFO, false);
addOption(options, null, OPTION_NO_DATA, false);
addOption(options, "i", OPTION_COMMENTS, false);
}
@Override
protected boolean executeOptions(CommandLine line) throws Exception {
DbExport dbExport = new DbExport(getDatabasePlatform());
if (line.hasOption(OPTION_FORMAT)) {
dbExport.setFormat(Format.valueOf(line.getOptionValue(OPTION_FORMAT).toUpperCase()));
}
if (line.hasOption(OPTION_COMPATIBLE)) {
dbExport.setCompatible(Compatible.valueOf(line.getOptionValue(OPTION_COMPATIBLE).toUpperCase()));
}
if (line.hasOption(OPTION_ADD_DROP_TABLE)) {
dbExport.setAddDropTable(true);
}
if (line.hasOption(OPTION_NO_CREATE_INFO)) {
dbExport.setNoCreateInfo(true);
}
if (line.hasOption(OPTION_NO_DATA)) {
dbExport.setNoData(true);
}
if (line.hasOption(OPTION_COMMENTS)) {
dbExport.setComments(true);
}
String[] args = line.getArgs();
if (args.length == 0) {
dbExport.exportTables(System.out);
} else {
dbExport.exportTables(System.out, args);
}
return true;
}
}