View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002141 | SymmetricDS | New Feature | public | 2015-01-16 18:49 | 2025-03-19 17:17 |
Reporter | vilius | Assigned To | |||
Priority | normal | ||||
Status | acknowledged | Resolution | open | ||
Summary | 0002141: [symadmin] Reload all tables in a specified catalog/schema | ||||
Description | symadmin reload-table currently allows to reload multiple tables, which might become cumbersome when trying to reload all tables of one schema. Proposed patch adds a wild-card mode to reload-table and orders table list (whether in wild-card mode or when the user specifies a list of tables) according to FKs. | ||||
Additional Information | http://sourceforge.net/p/symmetricds/discussion/739236/thread/0ecf4444/ | ||||
Tags | initial/partial load, symadmin | ||||
|
trunk.patch (8,236 bytes)
### Eclipse Workspace Patch 1.0 #P symmetric-core Index: src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterService.java =================================================================== --- src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterService.java (revision 9284) +++ src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterService.java (working copy) @@ -41,6 +41,7 @@ import org.jumpmind.db.model.Table; import org.jumpmind.db.sql.ISqlRowMapper; import org.jumpmind.db.sql.Row; +import org.jumpmind.db.sql.mapper.StringMapper; import org.jumpmind.symmetric.ISymmetricEngine; import org.jumpmind.symmetric.Version; import org.jumpmind.symmetric.common.Constants; @@ -159,6 +160,28 @@ return sqlTemplate.query("select " + getSql("selectTriggersColumnList", "selectTriggersSql"), new TriggerMapper()); } + + /** + * @param sourceCatalog if null, will not be included in WHERE + * @param sourceSchema if null, will not be included in WHERE + */ + @Override + public List<String> getSourceTableNames(String sourceCatalog, String sourceSchema) { + String where = ""; + Object[] args = null; + if (sourceCatalog != null && sourceSchema != null) { + where = " where t.source_catalog_name = ? and t.source_schema_name = ?"; + args = new Object[] {sourceCatalog, sourceSchema}; + } else if (sourceCatalog != null) { + where = " where t.source_catalog_name = ?"; + args = new Object[] {sourceCatalog}; + } else if (sourceSchema != null) { + where = " where t.source_schema_name = ?"; + args = new Object[] {sourceSchema}; + } + + return sqlTemplate.query(getSql("selectSourceTableNames") + where, new StringMapper(), args); + } public boolean isTriggerBeingUsed(String triggerId) { return sqlTemplate.queryForInt(getSql("countTriggerRoutersByTriggerIdSql"), triggerId) > 0; Index: src/main/java/org/jumpmind/symmetric/service/ITriggerRouterService.java =================================================================== --- src/main/java/org/jumpmind/symmetric/service/ITriggerRouterService.java (revision 9284) +++ src/main/java/org/jumpmind/symmetric/service/ITriggerRouterService.java (working copy) @@ -187,4 +187,5 @@ public Collection<Trigger> findMatchingTriggers(List<Trigger> triggers, String catalog, String schema, String table); + public List<String> getSourceTableNames(String sourceCatalog, String sourceSchema); } \ No newline at end of file Index: src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterServiceSqlMap.java =================================================================== --- src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterServiceSqlMap.java (revision 9284) +++ src/main/java/org/jumpmind/symmetric/service/impl/TriggerRouterServiceSqlMap.java (working copy) @@ -196,7 +196,7 @@ putSql("selectMaxRouterLastUpdateTime" ,"select max(last_update_time) from $(router) where last_update_time is not null" ); putSql("selectMaxTriggerRouterLastUpdateTime" ,"select max(last_update_time) from $(trigger_router) where last_update_time is not null" ); - + putSql("selectSourceTableNames", "select distinct source_table_name from $(trigger) t"); } } \ No newline at end of file #P symmetric-client Index: src/main/java/org/jumpmind/symmetric/SymmetricAdmin.java =================================================================== --- src/main/java/org/jumpmind/symmetric/SymmetricAdmin.java (revision 9284) +++ src/main/java/org/jumpmind/symmetric/SymmetricAdmin.java (working copy) @@ -44,6 +44,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.h2.util.StringUtils; +import org.jumpmind.db.model.Database; import org.jumpmind.db.model.Table; import org.jumpmind.security.ISecurityService; import org.jumpmind.security.SecurityConstants; @@ -500,16 +501,41 @@ System.out.println("ERROR: Expected argument for: Table Name"); System.exit(1); } + + if (args.size() == 1 && "*".equals(args.get(0))) { + if (catalogName != null || schemaName != null) { + args = getSymmetricEngine().getTriggerRouterService().getSourceTableNames(catalogName, schemaName); + } else { + /* + * with neither catalog nor schema specified there's a high risk to lookup the wrong database object if there's more than one with + * the same name. + */ + System.out.println("ERROR: Please specify catalog and/or schema for wildcard mode"); + System.exit(1); + } + } + + List<Table> tables = new ArrayList<Table>(args.size()); for (String tableName : args) { + Table t = getDatabasePlatform(true).getTableFromCache(catalogName, schemaName, tableName, false); + if (t != null) { + tables.add(t); + } else { + System.out.println("ERROR: Unable to lookup table " + tableName); + } + } + tables = Database.sortByForeignKeys(tables); + + for (Table table : tables) { for (Node node : getNodes(line)) { - System.out.println("Reloading table '" + tableName + "' to node '" + node.getNodeId() + "'"); + System.out.println("Reloading table '" + table.getName() + "' to node '" + node.getNodeId() + "'"); if (line.hasOption(OPTION_WHERE)) { - System.out.println(getSymmetricEngine().getDataService().reloadTable(node.getNodeId(), catalogName, - schemaName, tableName, line.getOptionValue(OPTION_WHERE))); + System.out.println(getSymmetricEngine().getDataService().reloadTable(node.getNodeId(), table.getCatalog(), + table.getSchema(), table.getName(), line.getOptionValue(OPTION_WHERE))); } else { - System.out.println(getSymmetricEngine().getDataService().reloadTable(node.getNodeId(), catalogName, - schemaName, tableName)); + System.out.println(getSymmetricEngine().getDataService().reloadTable(node.getNodeId(), table.getCatalog(), + table.getSchema(), table.getName())); } } } Index: src/main/resources/symmetric-messages.properties =================================================================== --- src/main/resources/symmetric-messages.properties (revision 9284) +++ src/main/resources/symmetric-messages.properties (working copy) @@ -98,7 +98,7 @@ SymAdmin.Help.encrypt-text=Encrypts the given text for use with db.user and db.password properties. SymAdmin.Help.create-war=Generate a web archive that can be deployed to a web server like Tomcat. The name of the output file must be provided. If a properties file is designated, it will be renamed and packaged as symmetric.properties. Other than the optional properties file, a war is made up of the contents of the web directory and the conf directory of the standalone installation. SymAdmin.Help.reload-node=Send an initial load of data to reload a remote node. -SymAdmin.Help.reload-table=Send the data from the specified tables to a node or group of nodes. +SymAdmin.Help.reload-table=Send the data from the specified tables to a node or group of nodes. '*' may be specified instead of the table list to reload all tables in the specified catalog/schema. SymAdmin.Help.send-sql=Send a SQL statement to be executed on a remote node. SymAdmin.Help.send-schema=Send a schema update for a table to be executed on a remote node. The table definition is sent in torque XML format. If the target table is missing, it is created; if it exists it will be altered, if possible, otherwise dropped and re-created. SymAdmin.Help.send-script=Send a script to a node to be run there. The script is read from the filename provided as an argument or read from standard input. Only BeanShell scripts are supported. |