final Configuration configuration = getConfiguration();
if (schemaUpdate) {
ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
SchemaUpdate update = new SchemaUpdate(builder.buildServiceRegistry(), configuration);
// classic schemaupdate execution, will work with all releases
if(outputFileName == null && delimiter == null && haltOnError && format)
update.execute(scriptToConsole, exportToDatabase);
// at least one of the parameter unmanaged by
// hibernate core prior versions is set
else {
/* working with reflection as no idea what hibernate core version is used */
try {
Class schemaUpdateClass = SchemaUpdate.class;
if (null != outputFileName) {
Method setOutputFile = schemaUpdateClass.getMethod("setOutputFile",
new Class[] {String.class});
setOutputFile.invoke(update, new Object[] {new File(getOutputDirectory(),
outputFileName).toString()});
log.debug("delimiter ='"+ delimiter + "'");
Method setDelimiter = schemaUpdateClass.getMethod("setDelimiter",
new Class[] {String.class});
setDelimiter.invoke(update, new Object[] {delimiter});
Method setFormat = schemaUpdateClass.getMethod("setFormat",
new Class[] {boolean.class});
setFormat.invoke(update, new Object[] {Boolean.valueOf(format)});
}
if (haltOnError) {
Method setHaltOnError = schemaUpdateClass.getMethod("setHaltOnError",
new Class[] {boolean.class});
setHaltOnError.invoke(update, new Object[] {Boolean.valueOf(haltOnError)});
}
update.execute(scriptToConsole, exportToDatabase);
if (!update.getExceptions().isEmpty()) {
int i = 1;
for (Iterator iterator = update.getExceptions().iterator(); iterator
.hasNext(); i++) {
Throwable element = (Throwable) iterator.next();
log.warn("Error #" + i + ": ", element);
}