private static void normalizeTopolgyData(ExchSite3[] groups) { for (int i = 0; i < groups.length; i++) { ExchSite3 site = groups[i]; site.setInternalName(DirectoryUtils.escapeCommas(site.getInternalName())); ExchServer3[] servers = site.getServers(); for (int j = 0; j < servers.length; j++) { ExchServer3 server = servers[j]; server.setInternalName(DirectoryUtils.escapeCommas(server.getInternalName())); ExchStore2[] stores = server.getStores(); for (int k = 0; k < stores.length; k++) { ExchStore2 store = stores[k]; store.setInternalName(DirectoryUtils.escapeCommas(store.getInternalName())); } } } }
private static Map saveStores( TopologyData3 td, int sourceID, ExchSite3[] sites, Map serverIDs, Connection c) throws SQLException { PreparedStatement insert = null; PreparedStatement delete = null; try { insert = c.prepareStatement( "insert into dat_customer_stores (store_id, source_id, server_id, internal_name, display_name) " + "values (?, ?, ?, ?, ?)"); delete = c.prepareStatement("delete from dat_customer_stores where store_id = ?"); Map storeIDs = new HashMap(101); for (int i = 0; i < sites.length; i++) { ExchSite3 site = sites[i]; ExchServer3[] servers = site.getServers(); for (int j = 0; j < servers.length; j++) { ExchServer3 server = servers[j]; int serverID = ((Number) serverIDs.get(server.getInternalName())).intValue(); ExchStore2[] stores = server.getStores(); for (int k = 0; k < stores.length; k++) { ExchStore2 store = stores[k]; int storeId = queryLookupStoreId(sourceID, store.getInternalName(), c); if (storeId == 0) { // if we couldn't find an existing storeID, grab the next one from the sequence storeId = getNextFromSequence("seq_store_id", c); } else { // if there is an existing storeID, delete it so we can insert the changes delete.setInt(1, storeId); int deleted = delete.executeUpdate(); if (deleted != 1) { throw new SQLException("Delete for store " + storeId + " returned " + deleted); } } storeIDs.put(store.getInternalName(), storeId); insert.setInt(1, storeId); insert.setInt(2, sourceID); insert.setInt(3, serverID); insert.setString( 4, DirectoryUtils.truncateString( store.getInternalName(), DB_STORE_INTERNALNAME_LENGTH)); insert.setString( 5, DirectoryUtils.truncateString(store.getDisplayName(), DB_STORE_DISPLAYNAME_LENGTH)); insert.executeUpdate(); } } } return storeIDs; } finally { if (delete != null) { delete.close(); } if (insert != null) { insert.close(); } } }