# HG changeset patch # User Sascha L. Teichmann # Date 1324052519 0 # Node ID 97de7a552b7920b80dda4347e51ac3c6015a5750 # Parent 039413d7e3946269876636aeb1e1d61f30f90076 Load DIPS XML flys-aft/trunk@3452 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 039413d7e394 -r 97de7a552b79 flys-aft/doc/conf.xml --- a/flys-aft/doc/conf.xml Fri Dec 16 11:26:12 2011 +0000 +++ b/flys-aft/doc/conf.xml Fri Dec 16 16:21:59 2011 +0000 @@ -1,5 +1,7 @@ + + diff -r 039413d7e394 -r 97de7a552b79 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Fri Dec 16 11:26:12 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Fri Dec 16 16:21:59 2011 +0000 @@ -26,13 +26,12 @@ return name; } - public void sync( - ConnectedStatements aftStatements, - ConnectedStatements flysStatements - ) - throws SQLException - { + public void sync(SyncContext context) throws SQLException { log.info("sync river: " + this); + + ConnectedStatements flysStatements = context.getFlysStatements(); + ConnectedStatements aftStatements = context.getAftStatements(); + ResultSet messstellenRs = aftStatements .getStatement("select.messstelle") .clearParameters() diff -r 039413d7e394 -r 97de7a552b79 flys-aft/src/main/java/de/intevation/aft/Rivers.java --- a/flys-aft/src/main/java/de/intevation/aft/Rivers.java Fri Dec 16 11:26:12 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/Rivers.java Fri Dec 16 16:21:59 2011 +0000 @@ -20,14 +20,13 @@ public Rivers() { } - public void sync( - ConnectedStatements aftStatements, - ConnectedStatements flysStatements - ) - throws SQLException - { + public void sync(SyncContext context) throws SQLException { + log.info("sync: rivers"); + ConnectedStatements flysStatements = context.getFlysStatements(); + ConnectedStatements aftStatements = context.getAftStatements(); + Map flysRivers = new HashMap(); ResultSet flysRs = flysStatements @@ -60,7 +59,7 @@ aftRs.close(); for (River river: commonRivers) { - river.sync(aftStatements, flysStatements); + river.sync(context); } } } diff -r 039413d7e394 -r 97de7a552b79 flys-aft/src/main/java/de/intevation/aft/Sync.java --- a/flys-aft/src/main/java/de/intevation/aft/Sync.java Fri Dec 16 11:26:12 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java Fri Dec 16 16:21:59 2011 +0000 @@ -6,16 +6,19 @@ import org.w3c.dom.Document; +import javax.xml.xpath.XPathConstants; + import de.intevation.utils.XML; import de.intevation.db.ConnectionBuilder; -import de.intevation.db.ConnectedStatements; public class Sync { public static final String FLYS = "flys"; public static final String AFT = "aft"; + public static final String XPATH_DIPS = "/sync/dips/@file"; + public static final String CONFIG_FILE = System.getProperty("config.file", "config.xml"); @@ -35,30 +38,50 @@ System.exit(1); } + String dipsF = (String)XML.xpath( + config, XPATH_DIPS, XPathConstants.STRING, null, null); + + if (dipsF == null || dipsF.length() == 0) { + System.err.println("Cannot find path to DiPS xml in config."); + System.exit(1); + } + + File dipsFile = new File(dipsF); + + if (!dipsFile.isFile() || !dipsFile.canRead()) { + System.err.println("Cannot find '" + dipsF + "'"); + System.exit(1); + } + + Document dips = XML.parseDocument(dipsFile, Boolean.FALSE); + + if (dips == null) { + System.err.println("Cannot load DiPs document."); + System.exit(1); + } + ConnectionBuilder aftConnectionBuilder = new ConnectionBuilder(AFT, config); ConnectionBuilder flysConnectionBuilder = new ConnectionBuilder(FLYS, config); - ConnectedStatements aftStatements = null; - ConnectedStatements flysStatements = null; + SyncContext syncContext = null; try { - aftStatements = aftConnectionBuilder.getConnectedStatements(); - flysStatements = flysConnectionBuilder.getConnectedStatements(); + syncContext = new SyncContext( + aftConnectionBuilder.getConnectedStatements(), + flysConnectionBuilder.getConnectedStatements(), + dips); Rivers rivers = new Rivers(); - rivers.sync(aftStatements, flysStatements); + rivers.sync(syncContext); } catch (SQLException sqle) { sqle.printStackTrace(); System.err.println("syncing failed: " + sqle.getMessage()); } finally { - if (aftStatements != null) { - aftStatements.close(); - } - if (flysStatements != null) { - flysStatements.close(); + if (syncContext != null) { + syncContext.close(); } } } diff -r 039413d7e394 -r 97de7a552b79 flys-aft/src/main/java/de/intevation/aft/SyncContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/SyncContext.java Fri Dec 16 16:21:59 2011 +0000 @@ -0,0 +1,56 @@ +package de.intevation.aft; + +import de.intevation.db.ConnectedStatements; + +import org.w3c.dom.Document; + +public class SyncContext +{ + protected ConnectedStatements aftStatements; + protected ConnectedStatements flysStatements; + protected Document dips; + + public SyncContext() { + } + + public SyncContext( + ConnectedStatements aftStatements, + ConnectedStatements flysStatements, + Document dips + ) { + this.aftStatements = aftStatements; + this.flysStatements = flysStatements; + this.dips = dips; + } + + public ConnectedStatements getAftStatements() { + return aftStatements; + } + + public void setAftStatements(ConnectedStatements aftStatements) { + this.aftStatements = aftStatements; + } + + public ConnectedStatements getFlysStatements() { + return flysStatements; + } + + public void setFlysStatements(ConnectedStatements flysStatements) { + this.flysStatements = flysStatements; + } + + public Document getDips() { + return dips; + } + + public void setDips(Document dips) { + this.dips = dips; + } + + void close() { + aftStatements.close(); + flysStatements.close(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +