diff --git a/symmetric-client/src/main/java/org/jumpmind/symmetric/util/SnapshotUtil.java b/symmetric-client/src/main/java/org/jumpmind/symmetric/util/SnapshotUtil.java
index d546a502ea..e030356c98 100644
--- a/symmetric-client/src/main/java/org/jumpmind/symmetric/util/SnapshotUtil.java
+++ b/symmetric-client/src/main/java/org/jumpmind/symmetric/util/SnapshotUtil.java
@@ -59,6 +59,7 @@
import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
+import org.jumpmind.db.model.CatalogSchema;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.Row;
@@ -134,16 +135,16 @@ public static File createSnapshot(ISymmetricEngine engine) {
log.warn("Failed to copy " + serviceConfFile.getName() + " to the snapshot directory", e);
}
- TreeSet
tables = new TreeSet();
FileOutputStream fos = null;
try {
+ HashMap> catalogSchemas = new HashMap>();
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
List triggerHistories = triggerRouterService.getActiveTriggerHistories();
for (TriggerHistory triggerHistory : triggerHistories) {
Table table = engine.getDatabasePlatform().getTableFromCache(triggerHistory.getSourceCatalogName(),
triggerHistory.getSourceSchemaName(), triggerHistory.getSourceTableName(), false);
if (table != null && !table.getName().toUpperCase().startsWith(engine.getSymmetricDialect().getTablePrefix().toUpperCase())) {
- tables.add(table);
+ addTableToMap(catalogSchemas, new CatalogSchema(table.getCatalog(), table.getSchema()), table);
}
}
@@ -152,15 +153,35 @@ public static File createSnapshot(ISymmetricEngine engine) {
Table table = engine.getDatabasePlatform().getTableFromCache(trigger.getSourceCatalogName(), trigger.getSourceSchemaName(),
trigger.getSourceTableName(), false);
if (table != null) {
- tables.add(table);
+ addTableToMap(catalogSchemas, new CatalogSchema(table.getCatalog(), table.getSchema()), table);
}
}
- fos = new FileOutputStream(new File(tmpDir, "table-definitions.xml"));
- DbExport export = new DbExport(engine.getDatabasePlatform());
- export.setFormat(Format.XML);
- export.setNoData(true);
- export.exportTables(fos, tables.toArray(new Table[tables.size()]));
+ for (CatalogSchema catalogSchema : catalogSchemas.keySet()) {
+ DbExport export = new DbExport(engine.getDatabasePlatform());
+ boolean isDefaultCatalog = StringUtils.equalsIgnoreCase(catalogSchema.getCatalog(), engine.getDatabasePlatform().getDefaultCatalog());
+ boolean isDefaultSchema = StringUtils.equalsIgnoreCase(catalogSchema.getSchema(), engine.getDatabasePlatform().getDefaultSchema());
+
+ if (isDefaultCatalog && isDefaultSchema) {
+ fos = new FileOutputStream(new File(tmpDir, "table-definitions.xml"));
+ } else {
+ String extra = "";
+ if (!isDefaultCatalog && catalogSchema.getCatalog() != null) {
+ extra += catalogSchema.getCatalog() + "-";
+ export.setCatalog(catalogSchema.getCatalog());
+ }
+ if (!isDefaultSchema && catalogSchema.getSchema() != null) {
+ extra += catalogSchema.getSchema();
+ export.setSchema(catalogSchema.getSchema());
+ }
+ fos = new FileOutputStream(new File(tmpDir, "table-definitions-" + extra + ".xml"));
+ }
+
+ List tables = catalogSchemas.get(catalogSchema);
+ export.setFormat(Format.XML);
+ export.setNoData(true);
+ export.exportTables(fos, tables.toArray(new Table[tables.size()]));
+ }
} catch (Exception e) {
log.warn("Failed to export table definitions", e);
} finally {
@@ -700,6 +721,15 @@ public static File createThreadsFile() {
return file;
}
+ private static void addTableToMap(HashMap> catalogSchemas, CatalogSchema catalogSchema, Table table) {
+ List tables = catalogSchemas.get(catalogSchema);
+ if (tables == null) {
+ tables = new ArrayList();
+ catalogSchemas.put(catalogSchema, tables);
+ }
+ tables.add(table);
+ }
+
static class SortedProperties extends Properties {
private static final long serialVersionUID = 1L;
diff --git a/symmetric-db/src/main/java/org/jumpmind/db/model/CatalogSchema.java b/symmetric-db/src/main/java/org/jumpmind/db/model/CatalogSchema.java
new file mode 100644
index 0000000000..4c245e8554
--- /dev/null
+++ b/symmetric-db/src/main/java/org/jumpmind/db/model/CatalogSchema.java
@@ -0,0 +1,80 @@
+/**
+ * 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 General Public License, version 3.0 (GPLv3)
+ * (the "License"); you may not use this file except in compliance
+ * with the License.
+ *
+ * You should have received a copy of the GNU General Public License,
+ * version 3.0 (GPLv3) along with this library; if not, see
+ * .
+ *
+ * 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.db.model;
+
+public class CatalogSchema {
+
+ private String catalog;
+
+ private String schema;
+
+ public CatalogSchema(String catalog, String schema) {
+ this.catalog = catalog;
+ this.schema = schema;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
+ result = prime * result + ((schema == null) ? 0 : schema.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CatalogSchema other = (CatalogSchema) obj;
+ if (catalog == null) {
+ if (other.catalog != null)
+ return false;
+ } else if (!catalog.equals(other.catalog))
+ return false;
+ if (schema == null) {
+ if (other.schema != null)
+ return false;
+ } else if (!schema.equals(other.schema))
+ return false;
+ return true;
+ }
+
+ 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;
+ }
+}