Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Integrate Envers and fix export to database flag

  • Loading branch information...
commit e7ce76484d053800d68bdde925a15e8039df18e3 1 parent a6837c7
@lukasz-antoniak lukasz-antoniak authored koentsje committed
Showing with 28 additions and 10 deletions.
  1. +28 −10 src/java/org/hibernate/tool/hbm2x/Hbm2DDLExporter.java
View
38 src/java/org/hibernate/tool/hbm2x/Hbm2DDLExporter.java
@@ -22,9 +22,11 @@
import java.util.Iterator;
import org.hibernate.cfg.Configuration;
-import org.hibernate.engine.jdbc.spi.JdbcServices;
+import org.hibernate.integrator.spi.Integrator;
+import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
@@ -63,7 +65,7 @@ protected boolean setupBoolProperty(String property, boolean defaultVal) {
protected void setupContext() {
- exportToDatabase = setupBoolProperty("exportToDatabase", exportToDatabase);
+ exportToDatabase = setupBoolProperty("export", exportToDatabase);
scriptToConsole = setupBoolProperty("scriptToConsole", scriptToConsole);
schemaUpdate = setupBoolProperty("schemaUpdate", schemaUpdate);
delimiter = getProperties().getProperty("delimiter", delimiter);
@@ -80,12 +82,14 @@ protected void cleanUpContext() {
}
protected void doStart() {
-
final Configuration configuration = getConfiguration();
+ ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+ builder.applySettings( configuration.getProperties() );
+ ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
+ integrateEnvers( configuration, serviceRegistry );
+
if (schemaUpdate) {
- ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
- builder.applySettings(configuration.getProperties());
- SchemaUpdate update = new SchemaUpdate(builder.buildServiceRegistry(), configuration);
+ SchemaUpdate update = new SchemaUpdate(serviceRegistry, configuration);
// classic schemaupdate execution, will work with all releases
if(outputFileName == null && delimiter == null && haltOnError && format)
@@ -158,10 +162,6 @@ protected void doStart() {
}
} else {
- ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
- builder.applySettings(configuration.getProperties());
- ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
- serviceRegistry.getService( JdbcServices.class );
SchemaExport export = new SchemaExport(serviceRegistry, configuration);
if (null != outputFileName) {
export.setOutputFile(new File(getOutputDirectory(),
@@ -182,6 +182,24 @@ protected void doStart() {
}
+ /**
+ * Integrate Hibernate Envers extension if present in the classpath.
+ */
+ private void integrateEnvers(Configuration configuration, ServiceRegistry serviceRegistry) {
+ // Omit building SessionFactory.
+ // TODO: Update this part when Integrator does not need SessionFactory for applying Hibernate extensions.
+ for ( Integrator integrator : serviceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
+ if ( "org.hibernate.envers.event.EnversIntegrator".equals( integrator.getClass().getName() ) ) {
+ integrator.integrate(
+ configuration,
+ null,
+ serviceRegistry.getService( SessionFactoryServiceRegistryFactory.class ).buildServiceRegistry( null, configuration )
+ );
+ break;
+ }
+ }
+ }
+
public void setExport(boolean export) {
exportToDatabase = export;
}
Please sign in to comment.
Something went wrong with that request. Please try again.