Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0001063: Add export-config and import-config command line options to
symadmin
- Loading branch information
Showing
4 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/DbExportUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jumpmind.symmetric.io.data; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.List; | ||
|
||
import org.jumpmind.db.model.Column; | ||
import org.jumpmind.db.model.Table; | ||
import org.jumpmind.db.platform.IDatabasePlatform; | ||
import org.jumpmind.symmetric.io.data.DbExport.Format; | ||
|
||
public class DbExportUtils { | ||
public static void extractConfigurationStandalone(IDatabasePlatform platform, List<String> tables, Writer out) throws IOException { | ||
DbExport export = new DbExport(platform); | ||
export.setFormat(Format.SQL); | ||
export.setNoCreateInfo(true); | ||
export.setUseQuotedIdentifiers(false); | ||
for (int i = tables.size() - 1; i >= 0; i--) { | ||
String tableName = platform.alterCaseToMatchDatabaseDefaultCase(tables.get(i)); | ||
out.write(String.format("delete from %s;\n", tableName)); | ||
} | ||
String quote = platform.getDdlBuilder().getDatabaseInfo().getDelimiterToken(); | ||
for (String tableName : tables) { | ||
String appendSql = "order by "; | ||
Table table = platform.getTableFromCache(null, null, tableName, false); | ||
if (table != null) { | ||
Column[] pkColumns = table.getPrimaryKeyColumns(); | ||
for (int j = 0; j < pkColumns.length; j++) { | ||
if (j > 0) { | ||
appendSql += ", "; | ||
} | ||
appendSql += quote + pkColumns[j].getName() + quote; | ||
} | ||
} | ||
export.setWhereClause(appendSql); | ||
out.write(export.exportTables(new String[] { tableName })); | ||
} | ||
} | ||
} |