Skip to content

Commit

Permalink
0005729: DBImport- Allow the UI specification of the catalog and schema
Browse files Browse the repository at this point in the history
to override the catalog and schema specs in XML imported file
  • Loading branch information
Philip Marzullo committed Mar 7, 2023
1 parent a95b884 commit 670aa8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Expand Up @@ -211,6 +211,8 @@ protected void importTablesFromCsvDquote(InputStream in, String tableName) {

protected void importTablesFromXml(InputStream in) {
XmlDataReader reader = new XmlDataReader(in);
reader.setCatalog(catalog);
reader.setSchema(schema);
DefaultDatabaseWriter writer = new DefaultDatabaseWriter(symmetricPlatform, buildDatabaseWriterSettings());
DataProcessor dataProcessor = new DataProcessor(reader, writer, "import");
dataProcessor.process();
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.io.DatabaseXmlUtil;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Database;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class XmlDataReader extends AbstractDataReader implements IDataReader {
protected XmlPullParser parser;
protected Statistics statistics = new Statistics();
protected List<Object> next = new ArrayList<Object>();
// These values will override the specification from the input stream
protected String catalog;
protected String schema;

public XmlDataReader(InputStream is) {
this(toReader(is));
Expand Down Expand Up @@ -83,8 +87,8 @@ protected void readNext() {
String columnName = null;
CsvData data = null;
Table table = null;
String catalog = null;
String schema = null;
String localCatalog = catalog;
String localSchema = schema;
int eventType = parser.next();
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
Expand Down Expand Up @@ -138,8 +142,8 @@ protected void readNext() {
next.add(table);
Database db = new Database();
db.setName("dbimport");
db.setCatalog(catalog);
db.setSchema(schema);
db.setCatalog(localCatalog);
db.setSchema(localSchema);
db.addTable(table);
String xml = DatabaseXmlUtil.toXml(db);
data = new CsvData(DataEventType.CREATE);
Expand All @@ -150,9 +154,9 @@ protected void readNext() {
String attributeName = parser.getAttributeName(i);
String attributeValue = parser.getAttributeValue(i);
if ("catalog".equalsIgnoreCase(attributeName)) {
catalog = attributeValue;
localCatalog = StringUtils.isBlank(catalog) ? attributeValue : catalog;
} else if ("schema".equalsIgnoreCase(attributeName)) {
schema = attributeValue;
localSchema = StringUtils.isBlank(schema) ? attributeValue : schema;
}
}
}
Expand Down Expand Up @@ -245,4 +249,20 @@ public Map<Batch, Statistics> getStatistics() {
map.put(batch, statistics);
return map;
}

public String getCatalog() {
return catalog;
}

public void setCatalog(String catalog) {
this.catalog = catalog;
}

public String getSchema() {
return schema;
}

public void setSchema(String schema) {
this.schema = schema;
}
}

0 comments on commit 670aa8b

Please sign in to comment.