equal
deleted
inserted
replaced
25 import info.globalcode.sql.dk.batch.BatchEncoder; |
25 import info.globalcode.sql.dk.batch.BatchEncoder; |
26 import info.globalcode.sql.dk.configuration.Configuration; |
26 import info.globalcode.sql.dk.configuration.Configuration; |
27 import info.globalcode.sql.dk.configuration.ConfigurationException; |
27 import info.globalcode.sql.dk.configuration.ConfigurationException; |
28 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
28 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
29 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
29 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
|
30 import info.globalcode.sql.dk.configuration.Loader; |
30 import info.globalcode.sql.dk.configuration.NameIdentified; |
31 import info.globalcode.sql.dk.configuration.NameIdentified; |
31 import info.globalcode.sql.dk.formatting.Formatter; |
32 import info.globalcode.sql.dk.formatting.Formatter; |
32 import info.globalcode.sql.dk.formatting.FormatterContext; |
33 import info.globalcode.sql.dk.formatting.FormatterContext; |
33 import info.globalcode.sql.dk.formatting.FormatterException; |
34 import info.globalcode.sql.dk.formatting.FormatterException; |
34 import info.globalcode.sql.dk.jmx.ConnectionManagement; |
35 import info.globalcode.sql.dk.jmx.ConnectionManagement; |
41 import java.sql.SQLException; |
42 import java.sql.SQLException; |
42 import java.util.Collection; |
43 import java.util.Collection; |
43 import java.util.logging.Level; |
44 import java.util.logging.Level; |
44 import java.util.logging.LogRecord; |
45 import java.util.logging.LogRecord; |
45 import java.util.logging.Logger; |
46 import java.util.logging.Logger; |
46 import javax.xml.bind.JAXBContext; |
|
47 import javax.xml.bind.Unmarshaller; |
|
48 |
47 |
49 /** |
48 /** |
50 * Entry point of the command line interface of SQL-DK. |
49 * Entry point of the command line interface of SQL-DK. |
51 * |
50 * |
52 * @author Ing. František Kučera (frantovo.cz) |
51 * @author Ing. František Kučera (frantovo.cz) |
62 public static final int EXIT_CLI_VALIDATE_ERROR = 5; // doc:CLI options validation error |
61 public static final int EXIT_CLI_VALIDATE_ERROR = 5; // doc:CLI options validation error |
63 public static final int EXIT_CONFIGURATION_ERROR = 6; // doc:configuration error |
62 public static final int EXIT_CONFIGURATION_ERROR = 6; // doc:configuration error |
64 public static final int EXIT_FORMATTING_ERROR = 7; // doc:formatting error |
63 public static final int EXIT_FORMATTING_ERROR = 7; // doc:formatting error |
65 public static final int EXIT_BATCH_ERROR = 8; // doc:batch error |
64 public static final int EXIT_BATCH_ERROR = 8; // doc:batch error |
66 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
65 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
67 private CLIOptions options; |
66 private final CLIOptions options; |
|
67 private final Loader configurationLoader = new Loader(); |
68 private Configuration configuration; |
68 private Configuration configuration; |
69 |
69 |
70 public static void main(String[] args) { |
70 public static void main(String[] args) { |
71 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
71 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
72 int exitCode; |
72 int exitCode; |
184 } |
184 } |
185 |
185 |
186 @Override |
186 @Override |
187 public Configuration getConfiguration() throws ConfigurationException { |
187 public Configuration getConfiguration() throws ConfigurationException { |
188 if (configuration == null) { |
188 if (configuration == null) { |
189 configuration = loadConfiguration(); |
189 configuration = configurationLoader.loadConfiguration(); |
190 } |
190 } |
191 return configuration; |
191 return configuration; |
192 } |
192 } |
193 |
193 |
194 private void installDefaultConfiguration() throws ConfigurationException { |
194 private void installDefaultConfiguration() throws ConfigurationException { |
201 Functions.installResource(Constants.EXAMPLE_CONFIG_FILE, Constants.CONFIG_FILE); |
201 Functions.installResource(Constants.EXAMPLE_CONFIG_FILE, Constants.CONFIG_FILE); |
202 log.log(Level.FINE, "Installing default config file: {0}", Constants.CONFIG_FILE); |
202 log.log(Level.FINE, "Installing default config file: {0}", Constants.CONFIG_FILE); |
203 } catch (IOException e) { |
203 } catch (IOException e) { |
204 throw new ConfigurationException("Unable to write example configuration to " + Constants.CONFIG_FILE, e); |
204 throw new ConfigurationException("Unable to write example configuration to " + Constants.CONFIG_FILE, e); |
205 } |
205 } |
206 } |
|
207 } |
|
208 |
|
209 private Configuration loadConfiguration() throws ConfigurationException { |
|
210 try { |
|
211 JAXBContext jaxb = JAXBContext.newInstance(Configuration.class); |
|
212 Unmarshaller u = jaxb.createUnmarshaller(); |
|
213 return (Configuration) u.unmarshal(Constants.CONFIG_FILE); |
|
214 } catch (Exception e) { |
|
215 throw new ConfigurationException("Unable to load configuration from " + Constants.CONFIG_FILE, e); |
|
216 } |
206 } |
217 } |
207 } |
218 |
208 |
219 private void generateBashCompletion() { |
209 private void generateBashCompletion() { |
220 if (configuration == null) { |
210 if (configuration == null) { |