java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
branchv_0
changeset 146 4f4f515df807
parent 144 d273d7c6dc0c
child 149 6a6f7b384591
--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Wed Jan 08 14:50:26 2014 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Wed Jan 08 19:18:52 2014 +0100
@@ -19,6 +19,8 @@
 
 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
 import info.globalcode.sql.dk.CLIOptions.MODE;
+import info.globalcode.sql.dk.batch.Batch;
+import info.globalcode.sql.dk.batch.BatchDecoder;
 import info.globalcode.sql.dk.batch.BatchException;
 import info.globalcode.sql.dk.batch.BatchEncoder;
 import info.globalcode.sql.dk.configuration.Configuration;
@@ -158,7 +160,18 @@
 		log.log(Level.FINE, "Prepared batch size: {0} bytes", length);
 	}
 
-	private void processExecuteBatch() {
+	private void processExecuteBatch() throws ConfigurationException, SQLException, FormatterException, BatchException {
+		BatchDecoder dec = new BatchDecoder();
+		Batch b = dec.decode(options.getInputStream());
+
+		DatabaseDefinition dd = getConfiguration().getDatabase(options.getDatabaseName());
+		FormatterDefinition fd = configuration.getFormatter(options.getFormatterName());
+		try (DatabaseConnection c = dd.connect(options.getDatabaseProperties())) {
+			log.log(Level.FINE, "Database connected");
+			try (Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream(), options.getFormatterProperties()))) {
+				c.executeBatch(b, f);
+			}
+		}
 	}
 
 	@Override