HHH-8003 Create "sqlDropString" method in Dialect to handle "if exists"
correctly
This commit is contained in:
parent
e25211380d
commit
7fe238ac70
|
@ -1933,6 +1933,18 @@ public abstract class Dialect implements ConversionContext {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String getDropTableString( String tableName ) {
|
||||
StringBuilder buf = new StringBuilder( "drop table " );
|
||||
if ( supportsIfExistsBeforeTableName() ) {
|
||||
buf.append( "if exists " );
|
||||
}
|
||||
buf.append( tableName ).append( getCascadeConstraintsString() );
|
||||
if ( supportsIfExistsAfterTableName() ) {
|
||||
buf.append( " if exists" );
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this dialect support column-level check constraints?
|
||||
*
|
||||
|
|
|
@ -134,15 +134,7 @@ public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenera
|
|||
}
|
||||
|
||||
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||
StringBuilder sqlDropString = new StringBuilder( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
sqlDropString.append( "if exists " );
|
||||
}
|
||||
sqlDropString.append( tableName ).append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
sqlDropString.append( " if exists" );
|
||||
}
|
||||
return new String[] { sqlDropString.toString() };
|
||||
return new String[] { dialect.getDropTableString( tableName ) };
|
||||
}
|
||||
|
||||
public Object generatorKey() {
|
||||
|
|
|
@ -211,15 +211,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
|
|||
}
|
||||
|
||||
public String[] sqlDropStrings(Dialect dialect) {
|
||||
StringBuilder sqlDropString = new StringBuilder( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
sqlDropString.append( "if exists " );
|
||||
}
|
||||
sqlDropString.append( tableName ).append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
sqlDropString.append( " if exists" );
|
||||
}
|
||||
return new String[] { sqlDropString.toString() };
|
||||
return new String[] { dialect.getDropTableString( tableName ) };
|
||||
}
|
||||
|
||||
public Object generatorKey() {
|
||||
|
|
|
@ -571,14 +571,6 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
|
|||
|
||||
@Override
|
||||
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||
StringBuilder sqlDropString = new StringBuilder().append( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
sqlDropString.append( "if exists " );
|
||||
}
|
||||
sqlDropString.append( tableName ).append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
sqlDropString.append( " if exists" );
|
||||
}
|
||||
return new String[] { sqlDropString.toString() };
|
||||
return new String[] { dialect.getDropTableString( tableName ) };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,15 +187,7 @@ public class TableStructure implements DatabaseStructure {
|
|||
|
||||
@Override
|
||||
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||
StringBuilder sqlDropString = new StringBuilder().append( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
sqlDropString.append( "if exists " );
|
||||
}
|
||||
sqlDropString.append( tableName ).append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
sqlDropString.append( " if exists" );
|
||||
}
|
||||
return new String[] { sqlDropString.toString() };
|
||||
return new String[] { dialect.getDropTableString( tableName ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -572,16 +572,7 @@ public class Table implements RelationalModel, Serializable {
|
|||
}
|
||||
|
||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||
StringBuilder buf = new StringBuilder( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
buf.append( "if exists " );
|
||||
}
|
||||
buf.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
|
||||
.append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
buf.append( " if exists" );
|
||||
}
|
||||
return buf.toString();
|
||||
return dialect.getDropTableString( getQualifiedName( dialect, defaultCatalog, defaultSchema ) );
|
||||
}
|
||||
|
||||
public PrimaryKey getPrimaryKey() {
|
||||
|
|
|
@ -268,16 +268,7 @@ public class Table extends AbstractTableSpecification implements Exportable {
|
|||
|
||||
@Override
|
||||
public String[] sqlDropStrings(Dialect dialect) {
|
||||
StringBuilder buf = new StringBuilder( "drop table " );
|
||||
if ( dialect.supportsIfExistsBeforeTableName() ) {
|
||||
buf.append( "if exists " );
|
||||
}
|
||||
buf.append( getQualifiedName( dialect ) )
|
||||
.append( dialect.getCascadeConstraintsString() );
|
||||
if ( dialect.supportsIfExistsAfterTableName() ) {
|
||||
buf.append( " if exists" );
|
||||
}
|
||||
return new String[] { buf.toString() };
|
||||
return new String[] { dialect.getDropTableString( getQualifiedName( dialect ) ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,13 @@ public class BasicConnectionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
try {
|
||||
Statement statement = jdbcCoord.getStatementPreparer().createStatement();
|
||||
jdbcCoord.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
String dropSql = getDialect().getDropTableString( "SANDBOX_JDBC_TST" );
|
||||
try {
|
||||
jdbcCoord.getResultSetReturn().execute( statement, dropSql );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// ignore if the DB doesn't support "if exists" and the table doesn't exist
|
||||
}
|
||||
jdbcCoord.getResultSetReturn().execute( statement,
|
||||
"create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||
|
|
|
@ -83,7 +83,13 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
|
||||
// set up some tables to use
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
String dropSql = getDialect().getDropTableString( "SANDBOX_JDBC_TST" );
|
||||
try {
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, dropSql );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// ignore if the DB doesn't support "if exists" and the table doesn't exist
|
||||
}
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
|
@ -141,8 +147,13 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
|
||||
// set up some tables to use
|
||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
String dropSql = getDialect().getDropTableString( "SANDBOX_JDBC_TST" );
|
||||
try {
|
||||
jdbcCoordinator.getResultSetReturn().execute( statement, dropSql );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// ignore if the DB doesn't support "if exists" and the table doesn't exist
|
||||
} jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||
jdbcCoordinator.release( statement );
|
||||
|
|
Loading…
Reference in New Issue