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.ConfigHelper;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger; 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) { public static void main(String[] args) {
try { try {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -506,7 +514,10 @@ public class SchemaExport {
if (importFile != null) { if (importFile != null) {
cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, importFile ); cfg.setProperty( Environment.HBM2DDL_IMPORT_FILES, importFile );
} }
SchemaExport se = new SchemaExport( cfg )
ServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
try {
SchemaExport se = new SchemaExport( serviceRegistry.getService( JdbcServices.class ), cfg )
.setHaltOnError( halt ) .setHaltOnError( halt )
.setOutputFile( outFile ) .setOutputFile( outFile )
.setDelimiter( delim ); .setDelimiter( delim );
@ -514,7 +525,10 @@ public class SchemaExport {
se.setFormat( true ); se.setFormat( true );
} }
se.execute( script, export, drop, create ); se.execute( script, export, drop, create );
}
finally {
serviceRegistry.destroy();
}
} }
catch ( Exception e ) { catch ( Exception e ) {
LOG.unableToCreateSchema(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.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
@ -94,6 +96,12 @@ public class SchemaUpdate {
formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); 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) { public static void main(String[] args) {
try { try {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -136,7 +144,13 @@ public class SchemaUpdate {
cfg.setProperties( props ); 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 ) { catch ( Exception e ) {
LOG.unableToRunSchemaUpdate(e); LOG.unableToRunSchemaUpdate(e);

View File

@ -31,10 +31,14 @@ import java.util.Properties;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NamingStrategy;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.jboss.logging.Logger; 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) { public static void main(String[] args) {
try { try {
Configuration cfg = new Configuration(); Configuration cfg = new Configuration();
@ -105,7 +115,13 @@ public class SchemaValidator {
cfg.setProperties( props ); 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 ) { catch ( Exception e ) {
LOG.unableToRunSchemaUpdate(e); LOG.unableToRunSchemaUpdate(e);