in src/main/java/software/amazon/documentdb/jdbc/DocumentDbMain.java [514:560]
private static void performExport(
final CommandLine commandLine,
final DocumentDbConnectionProperties properties,
final StringBuilder output) throws SQLException {
// Determine if output file is required.
final File outputFile;
if (commandLine.hasOption(OUTPUT_OPTION_FLAG)) {
outputFile = tryGetOutputFile(commandLine, output);
if (outputFile == null) {
return;
}
} else {
outputFile = null;
}
final String[] requestedTableNames = commandLine.getOptionValues(EXPORT_OPTION_FLAG);
final List<String> requestedTableList = requestedTableNames != null
? Arrays.asList(requestedTableNames)
: new ArrayList<>();
final DocumentDbDatabaseSchemaMetadata schema = DocumentDbDatabaseSchemaMetadata.get(
properties,
properties.getSchemaName(),
VERSION_LATEST_OR_NONE,
getMongoClient(properties));
if (schema == null) {
// No schema to export.
return;
}
final Set<String> availTableSet = schema.getTableSchemaMap().keySet();
if (requestedTableList.isEmpty()) {
requestedTableList.addAll(availTableSet);
} else if (verifyRequestedTablesExist(requestedTableList, availTableSet, output)) {
return;
}
final List<TableSchema> tableSchemaList = requestedTableList.stream()
.map(tableName -> new TableSchema(schema.getTableSchemaMap().get(tableName)))
.sorted(Comparator.comparing(TableSchema::getSqlName))
.collect(Collectors.toList());
try {
writeTableSchemas(tableSchemaList, outputFile, output);
} catch (IOException e) {
output.append(e.getClass().getSimpleName())
.append(" ")
.append(e.getMessage());
}
}