}
}
@SuppressWarnings("unchecked")
public static void main(Configuration configuration) throws Exception {
Jdbc j = configuration.getJdbc();
org.jooq.util.jaxb.Generator g = configuration.getGenerator();
// Some default values for optional elements to avoid NPE's
if (g.getStrategy() == null)
g.setStrategy(new Strategy());
if (g.getTarget() == null)
g.setTarget(new Target());
Class.forName(j.getDriver());
Connection connection = null;
try {
// Initialise connection
// ---------------------
Properties properties = new Properties();
for (Property p : j.getProperties()) {
properties.put(p.getKey(), p.getValue());
}
if (!properties.containsKey("user"))
properties.put("user", defaultString(j.getUser()));
if (!properties.containsKey("password"))
properties.put("password", defaultString(j.getPassword()));
connection = DriverManager.getConnection(defaultString(j.getUrl()), properties);
// Initialise generator
// --------------------
Class<Generator> generatorClass = (Class<Generator>) (!isBlank(g.getName())
? Class.forName(trim(g.getName()))
: DefaultGenerator.class);
Generator generator = generatorClass.newInstance();
Class<GeneratorStrategy> strategyClass = (Class<GeneratorStrategy>) (!isBlank(g.getStrategy().getName())
? Class.forName(trim(g.getStrategy().getName()))
: DefaultGeneratorStrategy.class);
GeneratorStrategy strategy = strategyClass.newInstance();
generator.setStrategy(strategy);
Class<Database> databaseClass = (Class<Database>) Class.forName(trim(g.getDatabase().getName()));
Database database = databaseClass.newInstance();
List<Schema> schemata = g.getDatabase().getSchemata();
if (schemata.isEmpty()) {
Schema schema = new Schema();
schema.setInputSchema(trim(g.getDatabase().getInputSchema()));
schema.setOutputSchema(trim(g.getDatabase().getOutputSchema()));
schemata.add(schema);
}
else {
if (!StringUtils.isBlank(g.getDatabase().getInputSchema())) {
log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/inputSchema and /configuration/generator/database/schemata");
}
if (!StringUtils.isBlank(g.getDatabase().getOutputSchema())) {
log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/outputSchema and /configuration/generator/database/schemata");
}
}
for (Schema schema : schemata) {
if (StringUtils.isBlank(schema.getInputSchema())) {
if (!StringUtils.isBlank(j.getSchema())) {
log.warn("WARNING: The configuration property jdbc.Schema is deprecated and will be removed in the future. Use /configuration/generator/database/inputSchema instead");
}
schema.setInputSchema(trim(j.getSchema()));
}
if (StringUtils.isBlank(schema.getOutputSchema())) {
schema.setOutputSchema(trim(schema.getInputSchema()));
}