mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-8003 Create "sqlDropString" method in Dialect to handle "if exists"
correctly
This commit is contained in:
parent
b5de4cda15
commit
18f0bd2f4a
@ -2012,6 +2012,18 @@ public boolean supportsIfExistsAfterTableName() {
|
||||
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 String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
||||
}
|
||||
|
||||
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 String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
||||
}
|
||||
|
||||
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 String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
||||
|
||||
@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 String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
||||
|
||||
@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
|
||||
|
@ -571,16 +571,7 @@ public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog,
|
||||
}
|
||||
|
||||
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 @@ private static String getTypeString(Column col, Dialect dialect) {
|
||||
|
||||
@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 void testBasicJdbcUsage() throws JDBCException {
|
||||
|
||||
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() );
|
||||
|
@ -80,7 +80,13 @@ public void testNonBatchingUsage() throws Exception {
|
||||
|
||||
// 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() );
|
||||
@ -138,8 +144,13 @@ public void testBatchingUsage() throws Exception {
|
||||
|
||||
// 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…
x
Reference in New Issue
Block a user