java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
branchv_0
changeset 146 4f4f515df807
parent 144 d273d7c6dc0c
child 149 6a6f7b384591
equal deleted inserted replaced
145:5f90decd3b59 146:4f4f515df807
    17  */
    17  */
    18 package info.globalcode.sql.dk;
    18 package info.globalcode.sql.dk;
    19 
    19 
    20 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
    20 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
    21 import info.globalcode.sql.dk.CLIOptions.MODE;
    21 import info.globalcode.sql.dk.CLIOptions.MODE;
       
    22 import info.globalcode.sql.dk.batch.Batch;
       
    23 import info.globalcode.sql.dk.batch.BatchDecoder;
    22 import info.globalcode.sql.dk.batch.BatchException;
    24 import info.globalcode.sql.dk.batch.BatchException;
    23 import info.globalcode.sql.dk.batch.BatchEncoder;
    25 import info.globalcode.sql.dk.batch.BatchEncoder;
    24 import info.globalcode.sql.dk.configuration.Configuration;
    26 import info.globalcode.sql.dk.configuration.Configuration;
    25 import info.globalcode.sql.dk.configuration.ConfigurationException;
    27 import info.globalcode.sql.dk.configuration.ConfigurationException;
    26 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
    28 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
   156 		BatchEncoder enc = new BatchEncoder();
   158 		BatchEncoder enc = new BatchEncoder();
   157 		int length = enc.encode(options.getSQLCommand(), options.getOutputStream());
   159 		int length = enc.encode(options.getSQLCommand(), options.getOutputStream());
   158 		log.log(Level.FINE, "Prepared batch size: {0} bytes", length);
   160 		log.log(Level.FINE, "Prepared batch size: {0} bytes", length);
   159 	}
   161 	}
   160 
   162 
   161 	private void processExecuteBatch() {
   163 	private void processExecuteBatch() throws ConfigurationException, SQLException, FormatterException, BatchException {
       
   164 		BatchDecoder dec = new BatchDecoder();
       
   165 		Batch b = dec.decode(options.getInputStream());
       
   166 
       
   167 		DatabaseDefinition dd = getConfiguration().getDatabase(options.getDatabaseName());
       
   168 		FormatterDefinition fd = configuration.getFormatter(options.getFormatterName());
       
   169 		try (DatabaseConnection c = dd.connect(options.getDatabaseProperties())) {
       
   170 			log.log(Level.FINE, "Database connected");
       
   171 			try (Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream(), options.getFormatterProperties()))) {
       
   172 				c.executeBatch(b, f);
       
   173 			}
       
   174 		}
   162 	}
   175 	}
   163 
   176 
   164 	@Override
   177 	@Override
   165 	public Configuration getConfiguration() throws ConfigurationException {
   178 	public Configuration getConfiguration() throws ConfigurationException {
   166 		if (configuration == null) {
   179 		if (configuration == null) {