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;
|
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?
|
* 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 {
|
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||||
StringBuilder sqlDropString = new StringBuilder( "drop table " );
|
return new String[] { dialect.getDropTableString( tableName ) };
|
||||||
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() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object generatorKey() {
|
public Object generatorKey() {
|
||||||
|
@ -211,15 +211,7 @@ public String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String[] sqlDropStrings(Dialect dialect) {
|
public String[] sqlDropStrings(Dialect dialect) {
|
||||||
StringBuilder sqlDropString = new StringBuilder( "drop table " );
|
return new String[] { dialect.getDropTableString( tableName ) };
|
||||||
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() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object generatorKey() {
|
public Object generatorKey() {
|
||||||
|
@ -571,14 +571,6 @@ public String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||||
StringBuilder sqlDropString = new StringBuilder().append( "drop table " );
|
return new String[] { dialect.getDropTableString( tableName ) };
|
||||||
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() };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,15 +187,7 @@ public String[] sqlCreateStrings(Dialect dialect) throws HibernateException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
public String[] sqlDropStrings(Dialect dialect) throws HibernateException {
|
||||||
StringBuilder sqlDropString = new StringBuilder().append( "drop table " );
|
return new String[] { dialect.getDropTableString( tableName ) };
|
||||||
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() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -571,16 +571,7 @@ public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||||
StringBuilder buf = new StringBuilder( "drop table " );
|
return dialect.getDropTableString( getQualifiedName( dialect, defaultCatalog, defaultSchema ) );
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrimaryKey getPrimaryKey() {
|
public PrimaryKey getPrimaryKey() {
|
||||||
|
@ -268,16 +268,7 @@ private static String getTypeString(Column col, Dialect dialect) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] sqlDropStrings(Dialect dialect) {
|
public String[] sqlDropStrings(Dialect dialect) {
|
||||||
StringBuilder buf = new StringBuilder( "drop table " );
|
return new String[] { dialect.getDropTableString( getQualifiedName( dialect ) ) };
|
||||||
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() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,7 +72,13 @@ public void testBasicJdbcUsage() throws JDBCException {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Statement statement = jdbcCoord.getStatementPreparer().createStatement();
|
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,
|
jdbcCoord.getResultSetReturn().execute( statement,
|
||||||
"create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
"create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||||
assertTrue( jdbcCoord.hasRegisteredResources() );
|
assertTrue( jdbcCoord.hasRegisteredResources() );
|
||||||
|
@ -80,7 +80,13 @@ public void testNonBatchingUsage() throws Exception {
|
|||||||
|
|
||||||
// set up some tables to use
|
// set up some tables to use
|
||||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
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) )" );
|
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
||||||
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
assertTrue( jdbcCoordinator.hasRegisteredResources() );
|
||||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||||
@ -138,8 +144,13 @@ public void testBatchingUsage() throws Exception {
|
|||||||
|
|
||||||
// set up some tables to use
|
// set up some tables to use
|
||||||
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
Statement statement = jdbcCoordinator.getStatementPreparer().createStatement();
|
||||||
jdbcCoordinator.getResultSetReturn().execute( statement, "drop table SANDBOX_JDBC_TST if exists" );
|
String dropSql = getDialect().getDropTableString( "SANDBOX_JDBC_TST" );
|
||||||
jdbcCoordinator.getResultSetReturn().execute( statement, "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
|
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( jdbcCoordinator.hasRegisteredResources() );
|
||||||
assertTrue( logicalConnection.isPhysicallyConnected() );
|
assertTrue( logicalConnection.isPhysicallyConnected() );
|
||||||
jdbcCoordinator.release( statement );
|
jdbcCoordinator.release( statement );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user