package com.avaje.util.codegen;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.server.core.EbeanServerInternal;
import com.avaje.ebean.server.plugin.Plugin;
import com.avaje.lib.SystemProperties;
import com.avaje.lib.log.LogFactory;
import com.avaje.lib.util.StringHelper;
/**
* <pre>
* <code>
*
* ## Mode = test the table types
* #ebean.codegen.mode=test
*
* ## Mode = generate code
* ebean.codegen.mode=generate
*
* ebean.codegen.regex
*
* ## patterns for database dictionary loading
* ebean.codegen.catalog
* ebean.codegen.schema
* ebean.codegen.table
* </code>
* </pre>
*
*/
public class MainCodeGenerator {
private static final Logger logger = LogFactory.get(MainCodeGenerator.class);
public static void main(String[] args) throws Exception {
try {
try {
// make sure SystemProperties is initialised before
// loading the codegen.properties
SystemProperties.getProperty("default.datasource");
SystemProperties.loadProperties("codegen.properties", false);
} catch (Exception ex){
String msg = "codegen.properties was not loaded.";
logger.log(Level.SEVERE, msg, ex);
}
EbeanServerInternal server = (EbeanServerInternal) Ebean.getServer(null);
Plugin plugin = server.getPlugin();
GenerateConfiguration config = new GenerateConfiguration(plugin);
GenerateController gen = new GenerateController(config);
String regex = null;
if (args.length > 0) {
regex = args[0];
} else {
// pattern to match against tables to determine
// if we should generate the code
regex = config.getProperty("codegen.regex", null);
}
if (regex == null){
String match = config.getProperty("codegen.match", null);
if (match != null){
// use wildcard matching converting
// * & % into appropriate regex expression
String regexAll = "[a-z_]*";
match = StringHelper.replaceString(match, "*", regexAll);
match = StringHelper.replaceString(match, "%", regexAll);
regex = "^"+match+"$";
}
}
gen.generate(regex);
} catch (Exception ex) {
ex.printStackTrace();
logger.log(Level.SEVERE, null, ex);
}
}
}
|