java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
branchv_0
changeset 144 d273d7c6dc0c
parent 106 e9c3583580c8
child 146 4f4f515df807
equal deleted inserted replaced
143:1336bb9a4499 144:d273d7c6dc0c
    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.BatchException;
       
    23 import info.globalcode.sql.dk.batch.BatchEncoder;
    22 import info.globalcode.sql.dk.configuration.Configuration;
    24 import info.globalcode.sql.dk.configuration.Configuration;
    23 import info.globalcode.sql.dk.configuration.ConfigurationException;
    25 import info.globalcode.sql.dk.configuration.ConfigurationException;
    24 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
    26 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
    25 import info.globalcode.sql.dk.configuration.FormatterDefinition;
    27 import info.globalcode.sql.dk.configuration.FormatterDefinition;
    26 import info.globalcode.sql.dk.configuration.NameIdentified;
    28 import info.globalcode.sql.dk.configuration.NameIdentified;
    94 			log.log(Level.SEVERE, "SQL problem", e);
    96 			log.log(Level.SEVERE, "SQL problem", e);
    95 			exitCode = EXIT_SQL_ERROR;
    97 			exitCode = EXIT_SQL_ERROR;
    96 		} catch (FormatterException e) {
    98 		} catch (FormatterException e) {
    97 			log.log(Level.SEVERE, "Formatting problem", e);
    99 			log.log(Level.SEVERE, "Formatting problem", e);
    98 			exitCode = EXIT_FORMATTING_ERROR;
   100 			exitCode = EXIT_FORMATTING_ERROR;
       
   101 		} catch (BatchException e) {
       
   102 			log.log(Level.SEVERE, "Batch problem", e);
       
   103 			exitCode = EXIT_FORMATTING_ERROR;
    99 		}
   104 		}
   100 
   105 
   101 		System.exit(exitCode);
   106 		System.exit(exitCode);
   102 	}
   107 	}
   103 
   108 
   104 	public CLIStarter(CLIOptions options) {
   109 	public CLIStarter(CLIOptions options) {
   105 		this.options = options;
   110 		this.options = options;
   106 	}
   111 	}
   107 
   112 
   108 	private void process() throws ConfigurationException, SQLException, FormatterException {
   113 	private void process() throws ConfigurationException, SQLException, FormatterException, BatchException {
   109 		MODE mode = options.getMode();
   114 		MODE mode = options.getMode();
   110 
   115 
   111 		/** Show info */
   116 		/** Show info */
   112 		if (!options.getShowInfo().isEmpty()) {
   117 		if (!options.getShowInfo().isEmpty()) {
   113 			PrintStream infoOut = mode == MODE.JUST_SHOW_INFO ? System.out : System.err;
   118 			PrintStream infoOut = mode == MODE.JUST_SHOW_INFO ? System.out : System.err;
   145 				c.executeQuery(options.getSQLCommand(), f);
   150 				c.executeQuery(options.getSQLCommand(), f);
   146 			}
   151 			}
   147 		}
   152 		}
   148 	}
   153 	}
   149 
   154 
   150 	private void processPrepareBatch() {
   155 	private void processPrepareBatch() throws BatchException {
       
   156 		BatchEncoder enc = new BatchEncoder();
       
   157 		int length = enc.encode(options.getSQLCommand(), options.getOutputStream());
       
   158 		log.log(Level.FINE, "Prepared batch size: {0} bytes", length);
   151 	}
   159 	}
   152 
   160 
   153 	private void processExecuteBatch() {
   161 	private void processExecuteBatch() {
   154 	}
   162 	}
   155 
   163