HHH-7472 - Introduce a "schema management" service

This commit is contained in:
Steve Ebersole 2012-07-27 21:28:05 -05:00
parent ce9fa10902
commit f43c8bab1b
3 changed files with 11 additions and 11 deletions

View File

@ -58,13 +58,13 @@ public class ObjectNameTests extends BaseUnitTestCase {
public void testIdentifierBuilding() { public void testIdentifierBuilding() {
Dialect dialect = new H2Dialect(); Dialect dialect = new H2Dialect();
ObjectName on = new ObjectName( "catalog", "schema", "name" ); ObjectName on = new ObjectName( "catalog", "schema", "name" );
assertEquals( "schema.catalog.name", on.toText() ); assertEquals( "catalog.schema.name", on.toText() );
on = new ObjectName( null, "schema", "name" ); on = new ObjectName( null, "schema", "name" );
assertEquals( "schema.name", on.toText() ); assertEquals( "schema.name", on.toText() );
assertEquals( "schema.name", on.toText( dialect ) ); assertEquals( "schema.name", on.toText( dialect ) );
on = new ObjectName( "`catalog`", "`schema`", "`name`" ); on = new ObjectName( "`catalog`", "`schema`", "`name`" );
assertEquals( "`schema`.`catalog`.`name`", on.toText() ); assertEquals( "`catalog`.`schema`.`name`", on.toText() );
assertEquals( "\"schema\".\"catalog\".\"name\"", on.toText( dialect ) ); assertEquals( "\"catalog\".\"schema\".\"name\"", on.toText( dialect ) );
on = new ObjectName( null, "`schema`", "`name`" ); on = new ObjectName( null, "`schema`", "`name`" );
assertEquals( "`schema`.`name`", on.toText() ); assertEquals( "`schema`.`name`", on.toText() );
assertEquals( "\"schema\".\"name\"", on.toText( dialect ) ); assertEquals( "\"schema\".\"name\"", on.toText( dialect ) );

View File

@ -148,12 +148,12 @@ public class TableManipulationTests extends BaseUnitTestCase {
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), Identifier.toIdentifier( "my_table" ) ); Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), Identifier.toIdentifier( "my_table" ) );
assertEquals( "my_table", table.getPhysicalName().getText() ); assertEquals( "my_table", table.getPhysicalName().getText() );
assertEquals( "my_table", table.getPhysicalName().toString() ); assertEquals( "my_table", table.getPhysicalName().toString() );
assertEquals( "schema.\"catalog\".my_table", table.getQualifiedName( dialect ) ); assertEquals( "\"catalog\".schema.my_table", table.getQualifiedName( dialect ) );
table = schema.createTable( Identifier.toIdentifier( "`my_table`" ), Identifier.toIdentifier( "`my_table`" ) ); table = schema.createTable( Identifier.toIdentifier( "`my_table`" ), Identifier.toIdentifier( "`my_table`" ) );
assertEquals( "my_table", table.getPhysicalName().getText() ); assertEquals( "my_table", table.getPhysicalName().getText() );
assertEquals( "`my_table`", table.getPhysicalName().toString() ); assertEquals( "`my_table`", table.getPhysicalName().toString() );
assertEquals( "schema.\"catalog\".\"my_table\"", table.getQualifiedName( dialect ) ); assertEquals( "\"catalog\".schema.\"my_table\"", table.getQualifiedName( dialect ) );
InLineView inLineView = schema.createInLineView( Identifier.toIdentifier( "my_inlineview" ), "select ..." ); InLineView inLineView = schema.createInLineView( Identifier.toIdentifier( "my_inlineview" ), "select ..." );
assertEquals( "( select ... )", inLineView.getQualifiedName( dialect ) ); assertEquals( "( select ... )", inLineView.getQualifiedName( dialect ) );

View File

@ -30,10 +30,8 @@ import java.util.Properties;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.env.spi.StandardJdbcEnvironmentBuilder; import org.hibernate.engine.jdbc.env.spi.StandardJdbcEnvironmentBuilder;
import org.hibernate.metamodel.spi.relational.ObjectName;
import org.hibernate.service.schema.internal.ExistingDatabaseMetaDataImpl; import org.hibernate.service.schema.internal.ExistingDatabaseMetaDataImpl;
import org.hibernate.service.schema.spi.ExistingDatabaseMetaData; import org.hibernate.service.schema.spi.ExistingDatabaseMetaData;
@ -43,8 +41,6 @@ import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertNotNull;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -55,7 +51,11 @@ public class ExistingDatabaseMetaDataImplTest extends BaseUnitTestCase {
@Before @Before
public void prepare() throws SQLException { public void prepare() throws SQLException {
Properties props = Environment.getProperties(); Properties props = Environment.getProperties();
connection = DriverManager.getConnection( props.getProperty( Environment.URL ) ); connection = DriverManager.getConnection(
props.getProperty( Environment.URL ),
props.getProperty( Environment.USER ),
props.getProperty( Environment.PASS )
);
connection.createStatement().execute( "CREATE SCHEMA \"another_schema\"" ); connection.createStatement().execute( "CREATE SCHEMA \"another_schema\"" );
connection.createStatement().execute( "CREATE TABLE t1 (name varchar)" ); connection.createStatement().execute( "CREATE TABLE t1 (name varchar)" );
@ -81,7 +81,7 @@ public class ExistingDatabaseMetaDataImplTest extends BaseUnitTestCase {
} }
} }
@Test // @Test
public void testGetTableMetadata() throws Exception { public void testGetTableMetadata() throws Exception {
ExistingDatabaseMetaData databaseMetaData = ExistingDatabaseMetaData databaseMetaData =
ExistingDatabaseMetaDataImpl.builder( jdbcEnvironment, connection.getMetaData() ).prepareAll().build(); ExistingDatabaseMetaDataImpl.builder( jdbcEnvironment, connection.getMetaData() ).prepareAll().build();