diff --git a/symmetric-client/src/main/java/org/jumpmind/symmetric/DbExport.java b/symmetric-client/src/main/java/org/jumpmind/symmetric/DbExport.java
index 85f2909b1f..a564c5dbf8 100644
--- a/symmetric-client/src/main/java/org/jumpmind/symmetric/DbExport.java
+++ b/symmetric-client/src/main/java/org/jumpmind/symmetric/DbExport.java
@@ -115,11 +115,13 @@ public String exportTables(Table[] tables) throws IOException {
}
public void exportTables(OutputStream output) throws IOException {
+ setDefaultSchemaAndCatalog();
Database database = platform.readDatabase(catalog, schema, new String[] {"TABLE"});
exportTables(output, database.getTables());
}
public void exportTables(OutputStream output, String[] tableNames) throws IOException {
+ setDefaultSchemaAndCatalog();
ArrayList
tableList = new ArrayList();
for (String tableName : tableNames) {
@@ -136,18 +138,12 @@ public void exportTables(OutputStream output, String[] tableNames) throws IOExce
}
public void exportTables(OutputStream output, String tableName, String sql) throws IOException {
+ setDefaultSchemaAndCatalog();
Table table = platform.getDdlReader().readTable(catalog, schema, tableName, sql);
exportTables(output, new Table[] { table }, sql);
}
-
- public void exportTables(OutputStream output, Table[] tables) throws IOException {
- exportTables(output, tables, null);
- }
- public void exportTables(OutputStream output, Table[] tables, String sql) throws IOException {
- final Writer writer = new OutputStreamWriter(output);
- final CsvWriter csvWriter = new CsvWriter(writer, ',');
-
+ protected void setDefaultSchemaAndCatalog() {
if (StringUtils.isBlank(schema)) {
schema = platform.getDefaultSchema();
}
@@ -155,6 +151,15 @@ public void exportTables(OutputStream output, Table[] tables, String sql) throws
if (StringUtils.isBlank(catalog)) {
catalog = platform.getDefaultCatalog();
}
+ }
+
+ public void exportTables(OutputStream output, Table[] tables) throws IOException {
+ exportTables(output, tables, null);
+ }
+
+ public void exportTables(OutputStream output, Table[] tables, String sql) throws IOException {
+ final Writer writer = new OutputStreamWriter(output);
+ final CsvWriter csvWriter = new CsvWriter(writer, ',');
tables = Database.sortByForeignKeys(tables);
diff --git a/symmetric-client/src/test/java/org/jumpmind/symmetric/DbExportImportTest.java b/symmetric-client/src/test/java/org/jumpmind/symmetric/DbExportImportTest.java
index 9475495554..a993644ea9 100644
--- a/symmetric-client/src/test/java/org/jumpmind/symmetric/DbExportImportTest.java
+++ b/symmetric-client/src/test/java/org/jumpmind/symmetric/DbExportImportTest.java
@@ -7,7 +7,9 @@
import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.Table;
+import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.IDatabasePlatform;
+import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.symmetric.DbExport.Compatible;
import org.jumpmind.symmetric.DbExport.Format;
import org.jumpmind.symmetric.service.impl.AbstractServiceTest;
@@ -15,6 +17,29 @@
public class DbExportImportTest extends AbstractServiceTest {
+ @Test
+ public void testExportTableInSchemaOnH2() throws Exception {
+ if (getPlatform().getName().equals(DatabaseNamesConstants.H2)) {
+ ISymmetricEngine engine = getSymmetricEngine();
+ DataSource ds = engine.getDataSource();
+ ISqlTemplate template = getPlatform().getSqlTemplate();
+ template.update("CREATE SCHEMA IF NOT EXISTS A");
+ template.update("CREATE TABLE IF NOT EXISTS A.TEST (ID INT, NOTES VARCHAR(100), PRIMARY KEY (ID))");
+ template.update("DELETE FROM A.TEST");
+ template.update("INSERT INTO A.TEST VALUES(1,'test')");
+
+ DbExport export = new DbExport(ds);
+ export.setSchema("A");
+ export.setFormat(Format.SQL);
+ export.setNoCreateInfo(false);
+ export.setNoData(false);
+
+ String output = export.exportTables(new String[] {"TEST"}).toLowerCase();
+
+ // TODO validate
+ }
+ }
+
@Test
public void exportTestDatabaseSQL() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
@@ -61,9 +86,9 @@ public void exportThenImport() throws Exception {
.getDefaultSchema());
export.setCatalog(getSymmetricEngine().getSymmetricDialect().getPlatform()
.getDefaultCatalog());
- String output = export.exportTables(new String[] {table.getName()});
-
- //System.out.println(output);
+ String output = export.exportTables(new String[] { table.getName() });
+
+ // System.out.println(output);
// TODO validate
}
diff --git a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/AbstractJdbcDdlReader.java b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/AbstractJdbcDdlReader.java
index f355c66038..a11c1b3293 100644
--- a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/AbstractJdbcDdlReader.java
+++ b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/AbstractJdbcDdlReader.java
@@ -156,8 +156,8 @@ protected List initColumnsForTable() {
result.add(new MetaDataColumnDescriptor("TABLE_NAME", Types.VARCHAR));
result.add(new MetaDataColumnDescriptor("TABLE_TYPE", Types.VARCHAR, "UNKNOWN"));
- result.add(new MetaDataColumnDescriptor("TABLE_CAT", Types.VARCHAR));
- result.add(new MetaDataColumnDescriptor("TABLE_SCHEM", Types.VARCHAR));
+ result.add(new MetaDataColumnDescriptor(getResultSetCatalogName(), Types.VARCHAR));
+ result.add(new MetaDataColumnDescriptor(getResultSetSchemaName(), Types.VARCHAR));
result.add(new MetaDataColumnDescriptor("REMARKS", Types.VARCHAR));
return result;
@@ -422,6 +422,14 @@ protected List getColumnsForIndex() {
public Database getDatabase(Connection connection) throws SQLException {
return readTables(null, null, null);
}
+
+ protected String getResultSetSchemaName() {
+ return "TABLE_SCHEM";
+ }
+
+ protected String getResultSetCatalogName() {
+ return "TABLE_CAT";
+ }
/*
* Reads the database model from the given connection.
@@ -536,6 +544,11 @@ public Table execute(Connection connection) throws SQLException {
try {
tableData = metaData.getTables(getTableNamePattern(table));
if (tableData != null && tableData.next()) {
+ ResultSetMetaData meta = tableData.getMetaData();
+ int count = meta.getColumnCount();
+ for (int i = 1 ; i <= count; i++) {
+ System.err.println(meta.getColumnName(i) + "=" + tableData.getObject(i));
+ }
Map values = readMetaData(tableData, initColumnsForTable());
return readTable(connection, metaData, values);
} else {
@@ -657,11 +670,11 @@ protected Table readTable(Connection connection, DatabaseMetaDataWrapper metaDat
table.setName(tableName);
table.setType(type);
- String catalog = (String) values.get("TABLE_CAT");
+ String catalog = (String) values.get(getResultSetCatalogName());
table.setCatalog(catalog);
metaData.setCatalog(catalog);
- String schema = (String) values.get("TABLE_SCHEM");
+ String schema = (String) values.get(getResultSetSchemaName());
table.setSchema(schema);
metaData.setSchemaPattern(schema);
@@ -1289,10 +1302,10 @@ public String determineSchemaOf(Connection connection, String schemaPattern, Tab
while (!found && tableData.next()) {
Map values = readMetaData(tableData, getColumnsForTable());
- String tableName = (String) values.get("TABLE_NAME");
+ String tableName = (String) values.get(getResultSetCatalogName());
if ((tableName != null) && (tableName.length() > 0)) {
- schema = (String) values.get("TABLE_SCHEM");
+ schema = (String) values.get(getResultSetSchemaName());
columnData = metaData.getColumns(tableName, getDefaultColumnPattern());
found = true;
diff --git a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/h2/H2DdlReader.java b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/h2/H2DdlReader.java
index dc343cb8ac..773df8cb65 100644
--- a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/h2/H2DdlReader.java
+++ b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/h2/H2DdlReader.java
@@ -71,6 +71,16 @@ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map initColumnsForColumn() {