Mercurial > dive4elements > river
view flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4089:859b4781554a
Prefetch existing time intervals from FLYS db.
flys-aft/trunk@3574 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 03 Jan 2012 12:25:06 +0000 |
parents | 44dc38ca8492 |
children | d556e29592f5 |
line wrap: on
line source
package de.intevation.aft; import java.io.File; import java.sql.SQLException; import org.w3c.dom.Document; import org.apache.log4j.Logger; import javax.xml.xpath.XPathConstants; import de.intevation.utils.XML; import de.intevation.db.ConnectionBuilder; public class Sync { private static Logger log = Logger.getLogger(Sync.class); public static final String FLYS = "flys"; public static final String AFT = "aft"; public static final String XPATH_DIPS = "/sync/dips/file/text()"; public static final String XPATH_REPAIR = "/sync/dips/repair/text()"; public static final String CONFIG_FILE = System.getProperty("config.file", "config.xml"); public static void main(String [] args) { File configFile = new File(CONFIG_FILE); if (!configFile.isFile() || !configFile.canRead()) { log.error("cannot read config file"); System.exit(1); } Document config = XML.parseDocument(configFile, Boolean.FALSE); if (config == null) { log.error("Cannot load config file."); System.exit(1); } String dipsF = (String)XML.xpath( config, XPATH_DIPS, XPathConstants.STRING, null, null); if (dipsF == null || dipsF.length() == 0) { log.error("Cannot find path to DIPS XML in config."); System.exit(1); } File dipsFile = new File(dipsF); if (!dipsFile.isFile() || !dipsFile.canRead()) { log.error("Cannot find '" + dipsF + "'"); System.exit(1); } Document dips = XML.parseDocument(dipsFile, Boolean.FALSE); if (dips == null) { log.error("Cannot load DIPS document."); System.exit(1); } String repairF = (String)XML.xpath( config, XPATH_REPAIR, XPathConstants.STRING, null, null); if (repairF != null && repairF.length() > 0) { File repairFile = new File(repairF); if (!repairFile.isFile() || !repairFile.canRead()) { log.warn("Cannot open DIPS repair XSLT file."); } else { Document fixed = XML.transform(dips, repairFile); if (fixed == null) { log.warn("Fixing DIPS failed"); } else { dips = fixed; } } } ConnectionBuilder aftConnectionBuilder = new ConnectionBuilder(AFT, config); ConnectionBuilder flysConnectionBuilder = new ConnectionBuilder(FLYS, config); SyncContext syncContext = null; try { syncContext = new SyncContext( aftConnectionBuilder.getConnectedStatements(), flysConnectionBuilder.getConnectedStatements(), dips); syncContext.init(); Rivers rivers = new Rivers(); rivers.sync(syncContext); } catch (SQLException sqle) { log.error("syncing failed", sqle); } finally { if (syncContext != null) { syncContext.close(); } } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :