HHH-10298 - Add new configuration type hibernate.hbm2dll.extra_physical_table_types
This commit is contained in:
parent
c7b8f73b46
commit
aefdda0978
|
@ -928,6 +928,15 @@ public interface AvailableSettings {
|
|||
* Oracle), this is disabled by default.
|
||||
*/
|
||||
String ENABLE_SYNONYMS = "hibernate.synonyms";
|
||||
|
||||
/**
|
||||
* Identifies a comma-separate list of values to specify extra table types,
|
||||
* other than the default "TABLE" value, to recognize as defining a physical table
|
||||
* by schema update, creation and validation.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
String EXTRA_PHYSICAL_TABLE_TYPES = "hibernate.hbm2dll.extra_physical_table_types";
|
||||
|
||||
/**
|
||||
* Unique columns and unique keys both use unique constraints in most dialects.
|
||||
|
@ -965,11 +974,4 @@ public interface AvailableSettings {
|
|||
*/
|
||||
String AUTO_SESSION_EVENTS_LISTENER = "hibernate.session.events.auto";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -236,12 +236,12 @@ public final class StringHelper {
|
|||
}
|
||||
|
||||
|
||||
public static String[] split(String seperators, String list) {
|
||||
return split( seperators, list, false );
|
||||
public static String[] split(String separators, String list) {
|
||||
return split( separators, list, false );
|
||||
}
|
||||
|
||||
public static String[] split(String seperators, String list, boolean include) {
|
||||
StringTokenizer tokens = new StringTokenizer( list, seperators, include );
|
||||
public static String[] split(String separators, String list, boolean include) {
|
||||
StringTokenizer tokens = new StringTokenizer( list, separators, include );
|
||||
String[] result = new String[tokens.countTokens()];
|
||||
int i = 0;
|
||||
while ( tokens.hasMoreTokens() ) {
|
||||
|
@ -250,6 +250,16 @@ public final class StringHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String[] splitTrimmingTokens(String separators, String list, boolean include) {
|
||||
StringTokenizer tokens = new StringTokenizer( list, separators, include );
|
||||
String[] result = new String[tokens.countTokens()];
|
||||
int i = 0;
|
||||
while ( tokens.hasMoreTokens() ) {
|
||||
result[i++] = tokens.nextToken().trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String unqualify(String qualifiedName) {
|
||||
int loc = qualifiedName.lastIndexOf( "." );
|
||||
return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( loc + 1 );
|
||||
|
|
|
@ -23,9 +23,12 @@ import org.hibernate.boot.model.naming.Identifier;
|
|||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.tool.schema.extract.spi.ColumnInformation;
|
||||
|
@ -49,6 +52,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
|||
|
||||
private final String[] tableTypes;
|
||||
|
||||
private String[] extraPhysicalTableTypes;
|
||||
|
||||
private final ExtractionContext extractionContext;
|
||||
|
||||
public InformationExtractorJdbcDatabaseMetaDataImpl(ExtractionContext extractionContext) {
|
||||
|
@ -56,11 +61,33 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
|||
|
||||
ConfigurationService configService = extractionContext.getServiceRegistry()
|
||||
.getService( ConfigurationService.class );
|
||||
|
||||
final String extraPhysycalTableTypesConfig = configService.getSetting(
|
||||
AvailableSettings.EXTRA_PHYSICAL_TABLE_TYPES,
|
||||
StandardConverters.STRING,
|
||||
""
|
||||
);
|
||||
if ( !"".equals( extraPhysycalTableTypesConfig.trim() ) ) {
|
||||
this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
|
||||
",;",
|
||||
extraPhysycalTableTypesConfig,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
final String[] tempTableTypes;
|
||||
if ( ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, configService.getSettings(), false ) ) {
|
||||
this.tableTypes = new String[] { "TABLE", "VIEW", "SYNONYM" };
|
||||
tempTableTypes = new String[] {"TABLE", "VIEW", "SYNONYM"};
|
||||
}
|
||||
else {
|
||||
this.tableTypes = new String[] { "TABLE", "VIEW" };
|
||||
tempTableTypes = new String[] {"TABLE", "VIEW"};
|
||||
}
|
||||
|
||||
if ( this.extraPhysicalTableTypes != null ) {
|
||||
this.tableTypes = ArrayHelper.join( tempTableTypes, this.extraPhysicalTableTypes );
|
||||
}
|
||||
else {
|
||||
this.tableTypes = tempTableTypes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +400,20 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
|||
}
|
||||
|
||||
protected boolean isPhysicalTableType(String tableType) {
|
||||
return "TABLE".equalsIgnoreCase( tableType );
|
||||
if ( extraPhysicalTableTypes == null ) {
|
||||
return "TABLE".equalsIgnoreCase( tableType );
|
||||
}
|
||||
else {
|
||||
if ( "TABLE".equalsIgnoreCase( tableType ) ) {
|
||||
return true;
|
||||
}
|
||||
for ( int i = 0; i < extraPhysicalTableTypes.length; i++ ) {
|
||||
if ( extraPhysicalTableTypes[i].equalsIgnoreCase( tableType ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue