System.out.println("Executed with " + Arrays.toString(args));
final String dropScriptFileName = args[0] + File.separator + "drop-tables-ejbca4-" + args[1] + ".sql";
final String createScriptFileName = args[0] + File.separator + "create-tables-ejbca4-" + args[1] + ".sql";
final String createScriptFileNameNdb = args[0] + File.separator + "create-tables-ejbca4-" + args[1] + "-ndbcluster.sql";
// Configure with our current persistence unit
final Ejb3Configuration ejb3Configuration = new Ejb3Configuration().configure("ejbca-pu", null);
final AnnotationConfiguration hibernateConfiguration = ejb3Configuration.getHibernateConfiguration();
try {
// Create drop script
final String[] dropScript = hibernateConfiguration.generateDropSchemaScript(Dialect.getDialect(ejb3Configuration.getProperties()));
StringBuilder sb = new StringBuilder();
for (String line : dropScript) {
sb.append(line);
sb.append(";\n");
}
System.out.println("Writing drop script to " + dropScriptFileName);
new FileOutputStream(dropScriptFileName).write(sb.toString().getBytes());
// Create create script(s)
final String[] createScript = hibernateConfiguration.generateSchemaCreationScript(Dialect.getDialect(ejb3Configuration.getProperties()));
sb = new StringBuilder();
for (String line : createScript) {
// Format nicely, so it looks more like the old, manually created ones.
if (line.startsWith("create")) {
line = line.replaceAll("create table", "CREATE TABLE");