HHH-5766 : New services are not wired into standalone SchemaExport, SchemaUpdate, and SchemaValidator

This commit is contained in:
Gail Badner 2011-03-09 03:24:25 -08:00
parent 32577a8a79
commit 121c039ecd
3 changed files with 54 additions and 10 deletions

View File

@ -55,6 +55,8 @@ import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger;
/**
@ -427,6 +429,12 @@ public class SchemaExport {
}
private static ServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new ServiceRegistryImpl( properties );
}
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
@ -506,15 +514,21 @@ public class SchemaExport {
if (importFile != null) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, importFile );
}
SchemaExport se = new SchemaExport( cfg )
.setHaltOnError( halt )
.setOutputFile( outFile )
.setDelimiter( delim );
if ( format ) {
se.setFormat( true );
}
se.execute( script, export, drop, create );
ServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
SchemaExport se = new SchemaExport( serviceRegistry.getService( JdbcServices.class ), cfg )
.setHaltOnError( halt )
.setOutputFile( outFile )
.setDelimiter( delim );
if ( format ) {
se.setFormat( true );
}
se.execute( script, export, drop, create );
}
finally {
serviceRegistry.destroy();
}
}
catch ( Exception e ) {
LOG.unableToCreateSchema(e);

View File

@ -46,6 +46,8 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger;
/**
@ -94,6 +96,12 @@ public class SchemaUpdate {
formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
}
private static ServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new ServiceRegistryImpl( properties );
}
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
@ -136,7 +144,13 @@ public class SchemaUpdate {
cfg.setProperties( props );
}
new SchemaUpdate( cfg ).execute( script, doUpdate );
ServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
new SchemaUpdate( serviceRegistry.getService( JdbcServices.class ), cfg ).execute( script, doUpdate );
}
finally {
serviceRegistry.destroy();
}
}
catch ( Exception e ) {
LOG.unableToRunSchemaUpdate(e);

View File

@ -31,10 +31,14 @@ import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger;
/**
@ -72,6 +76,12 @@ public class SchemaValidator {
);
}
private static ServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return new ServiceRegistryImpl( properties );
}
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
@ -105,7 +115,13 @@ public class SchemaValidator {
cfg.setProperties( props );
}
new SchemaValidator( cfg ).validate();
ServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
new SchemaValidator( serviceRegistry.getService( JdbcServices.class ), cfg ).validate();
}
finally {
serviceRegistry.destroy();
}
}
catch ( Exception e ) {
LOG.unableToRunSchemaUpdate(e);