HHH-6669 : Manual SchemaExport broken due to temp code comments
This commit is contained in:
parent
24e3d1ce72
commit
3e3250e2a9
|
@ -27,9 +27,13 @@ package org.hibernate.tool.hbm2ddl;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
import org.hibernate.service.internal.BasicServiceRegistryImpl;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
/**
|
||||
* A {@link ConnectionHelper} implementation based on an internally
|
||||
|
@ -39,7 +43,7 @@ import org.hibernate.service.spi.Stoppable;
|
|||
*/
|
||||
class ManagedProviderConnectionHelper implements ConnectionHelper {
|
||||
private Properties cfgProperties;
|
||||
private ConnectionProvider connectionProvider;
|
||||
private BasicServiceRegistryImpl serviceRegistry;
|
||||
private Connection connection;
|
||||
|
||||
public ManagedProviderConnectionHelper(Properties cfgProperties) {
|
||||
|
@ -47,14 +51,18 @@ class ManagedProviderConnectionHelper implements ConnectionHelper {
|
|||
}
|
||||
|
||||
public void prepare(boolean needsAutoCommit) throws SQLException {
|
||||
/* TEMP TEMP TEMP
|
||||
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
||||
connection = connectionProvider.getConnection();
|
||||
if ( needsAutoCommit && !connection.getAutoCommit() ) {
|
||||
serviceRegistry = createServiceRegistry( cfgProperties );
|
||||
connection = serviceRegistry.getService( ConnectionProvider.class ).getConnection();
|
||||
if ( needsAutoCommit && ! connection.getAutoCommit() ) {
|
||||
connection.commit();
|
||||
connection.setAutoCommit( true );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private static BasicServiceRegistryImpl createServiceRegistry(Properties properties) {
|
||||
Environment.verifyProperties( properties );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
return (BasicServiceRegistryImpl) new ServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
|
@ -62,18 +70,38 @@ class ManagedProviderConnectionHelper implements ConnectionHelper {
|
|||
}
|
||||
|
||||
public void release() throws SQLException {
|
||||
try {
|
||||
releaseConnection();
|
||||
}
|
||||
finally {
|
||||
releaseServiceRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseConnection() throws SQLException {
|
||||
if ( connection != null ) {
|
||||
try {
|
||||
new SqlExceptionHelper().logAndClearWarnings( connection );
|
||||
connectionProvider.closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
if ( connectionProvider instanceof Stoppable ) {
|
||||
( ( Stoppable ) connectionProvider ).stop();
|
||||
try {
|
||||
serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
connection = null;
|
||||
}
|
||||
connectionProvider = null;
|
||||
}
|
||||
}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
private void releaseServiceRegistry() {
|
||||
if ( serviceRegistry != null ) {
|
||||
try {
|
||||
serviceRegistry.destroy();
|
||||
}
|
||||
finally {
|
||||
serviceRegistry = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class SchemaExportManagedConnectionTest extends SchemaExportTest {
|
||||
@Override
|
||||
protected SchemaExport createSchemaExport(Configuration cfg) {
|
||||
return new SchemaExport( cfg );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class SchemaExportSuppliedConnectionTest extends SchemaExportTest {
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
serviceRegistry = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SchemaExport createSchemaExport(Configuration cfg) {
|
||||
return new SchemaExport( serviceRegistry, cfg );
|
||||
}
|
||||
}
|
|
@ -28,10 +28,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
|
||||
|
@ -40,31 +36,16 @@ import static org.junit.Assert.assertEquals;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class SchemaExportTest extends BaseUnitTestCase {
|
||||
public abstract class SchemaExportTest extends BaseUnitTestCase {
|
||||
private final String MAPPING = "org/hibernate/test/schemaupdate/mapping.hbm.xml";
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
serviceRegistry = null;
|
||||
}
|
||||
|
||||
protected JdbcServices getJdbcServices() {
|
||||
return serviceRegistry.getService( JdbcServices.class );
|
||||
}
|
||||
protected abstract SchemaExport createSchemaExport(Configuration cfg);
|
||||
|
||||
@Test
|
||||
public void testCreateAndDropOnlyType() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.addResource( MAPPING );
|
||||
SchemaExport schemaExport = new SchemaExport( serviceRegistry, cfg );
|
||||
SchemaExport schemaExport = createSchemaExport( cfg );
|
||||
// create w/o dropping first; (OK because tables don't exist yet
|
||||
schemaExport.execute( false, true, false, true );
|
||||
assertEquals( 0, schemaExport.getExceptions().size() );
|
||||
|
@ -82,7 +63,7 @@ public class SchemaExportTest extends BaseUnitTestCase {
|
|||
public void testBothType() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.addResource( MAPPING );
|
||||
SchemaExport schemaExport = new SchemaExport( serviceRegistry, cfg );
|
||||
SchemaExport schemaExport = createSchemaExport( cfg );
|
||||
// drop before create (nothing to drop yeT)
|
||||
schemaExport.execute( false, true, false, false );
|
||||
assertEquals( 0, schemaExport.getExceptions().size() );
|
||||
|
@ -98,7 +79,7 @@ public class SchemaExportTest extends BaseUnitTestCase {
|
|||
public void testCreateAndDrop() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.addResource( MAPPING );
|
||||
SchemaExport schemaExport = new SchemaExport( serviceRegistry, cfg );
|
||||
SchemaExport schemaExport = createSchemaExport( cfg );
|
||||
// should drop before creating, but tables don't exist yet
|
||||
schemaExport.create( false, true);
|
||||
assertEquals( 0, schemaExport.getExceptions().size() );
|
||||
|
|
Loading…
Reference in New Issue