comparison flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4077:97de7a552b79

Load DIPS XML flys-aft/trunk@3452 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 16 Dec 2011 16:21:59 +0000
parents dbd0b3b1b8b8
children 44dc38ca8492
comparison
equal deleted inserted replaced
4076:039413d7e394 4077:97de7a552b79
4 4
5 import java.sql.SQLException; 5 import java.sql.SQLException;
6 6
7 import org.w3c.dom.Document; 7 import org.w3c.dom.Document;
8 8
9 import javax.xml.xpath.XPathConstants;
10
9 import de.intevation.utils.XML; 11 import de.intevation.utils.XML;
10 12
11 import de.intevation.db.ConnectionBuilder; 13 import de.intevation.db.ConnectionBuilder;
12 import de.intevation.db.ConnectedStatements;
13 14
14 public class Sync 15 public class Sync
15 { 16 {
16 public static final String FLYS = "flys"; 17 public static final String FLYS = "flys";
17 public static final String AFT = "aft"; 18 public static final String AFT = "aft";
19
20 public static final String XPATH_DIPS = "/sync/dips/@file";
18 21
19 public static final String CONFIG_FILE = 22 public static final String CONFIG_FILE =
20 System.getProperty("config.file", "config.xml"); 23 System.getProperty("config.file", "config.xml");
21 24
22 public static void main(String [] args) { 25 public static void main(String [] args) {
33 if (config == null) { 36 if (config == null) {
34 System.err.println("cannot load config"); 37 System.err.println("cannot load config");
35 System.exit(1); 38 System.exit(1);
36 } 39 }
37 40
41 String dipsF = (String)XML.xpath(
42 config, XPATH_DIPS, XPathConstants.STRING, null, null);
43
44 if (dipsF == null || dipsF.length() == 0) {
45 System.err.println("Cannot find path to DiPS xml in config.");
46 System.exit(1);
47 }
48
49 File dipsFile = new File(dipsF);
50
51 if (!dipsFile.isFile() || !dipsFile.canRead()) {
52 System.err.println("Cannot find '" + dipsF + "'");
53 System.exit(1);
54 }
55
56 Document dips = XML.parseDocument(dipsFile, Boolean.FALSE);
57
58 if (dips == null) {
59 System.err.println("Cannot load DiPs document.");
60 System.exit(1);
61 }
62
38 ConnectionBuilder aftConnectionBuilder = 63 ConnectionBuilder aftConnectionBuilder =
39 new ConnectionBuilder(AFT, config); 64 new ConnectionBuilder(AFT, config);
40 65
41 ConnectionBuilder flysConnectionBuilder = 66 ConnectionBuilder flysConnectionBuilder =
42 new ConnectionBuilder(FLYS, config); 67 new ConnectionBuilder(FLYS, config);
43 68
44 ConnectedStatements aftStatements = null; 69 SyncContext syncContext = null;
45 ConnectedStatements flysStatements = null;
46 try { 70 try {
47 aftStatements = aftConnectionBuilder.getConnectedStatements(); 71 syncContext = new SyncContext(
48 flysStatements = flysConnectionBuilder.getConnectedStatements(); 72 aftConnectionBuilder.getConnectedStatements(),
73 flysConnectionBuilder.getConnectedStatements(),
74 dips);
49 Rivers rivers = new Rivers(); 75 Rivers rivers = new Rivers();
50 rivers.sync(aftStatements, flysStatements); 76 rivers.sync(syncContext);
51 } 77 }
52 catch (SQLException sqle) { 78 catch (SQLException sqle) {
53 sqle.printStackTrace(); 79 sqle.printStackTrace();
54 System.err.println("syncing failed: " + sqle.getMessage()); 80 System.err.println("syncing failed: " + sqle.getMessage());
55 } 81 }
56 finally { 82 finally {
57 if (aftStatements != null) { 83 if (syncContext != null) {
58 aftStatements.close(); 84 syncContext.close();
59 }
60 if (flysStatements != null) {
61 flysStatements.close();
62 } 85 }
63 } 86 }
64 } 87 }
65 } 88 }
66 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 89 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org