HHH-11740 : Default MultiTableBulkIdStrategy for DB2 does not work with connection pools

(cherry picked from commit 061a1cae31)
This commit is contained in:
Gail Badner 2017-05-12 13:49:29 -07:00
parent d28663cbff
commit 1d7ed4aa55
2 changed files with 38 additions and 2 deletions

View File

@ -6,6 +6,12 @@
*/
package org.hibernate.dialect;
import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.AfterUseAction;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
/**
* An SQL dialect for DB2 9.7.
*
@ -18,4 +24,29 @@ public class DB297Dialect extends DB2Dialect {
// DB2 9.7 and later support "cross join"
return " cross join ";
}
@Override
public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() {
// Starting in DB2 9.7, "real" global temporary tables that can be shared between sessions
// are supported; (obviously) data is not shared between sessions.
return new GlobalTemporaryTableBulkIdStrategy(
new IdTableSupportStandardImpl() {
@Override
public String generateIdTableName(String baseName) {
return super.generateIdTableName( baseName );
}
@Override
public String getCreateIdTableCommand() {
return "create global temporary table";
}
@Override
public String getCreateIdTableStatementOptions() {
return "not logged";
}
},
AfterUseAction.CLEAN
);
}
}

View File

@ -33,6 +33,7 @@ import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.AfterUseAction;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper;
@ -397,7 +398,10 @@ public class DB2Dialect extends Dialect {
@Override
public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() {
return new GlobalTemporaryTableBulkIdStrategy(
// Prior to DB2 9.7, "real" global temporary tables that can be shared between sessions
// are *not* supported; even though the DB2 command says to declare a "global" temp table
// Hibernate treats it as a "local" temp table.
return new LocalTemporaryTableBulkIdStrategy(
new IdTableSupportStandardImpl() {
@Override
public String generateIdTableName(String baseName) {
@ -414,7 +418,8 @@ public class DB2Dialect extends Dialect {
return "not logged";
}
},
AfterUseAction.CLEAN
AfterUseAction.DROP,
null
);
}