HHH-14921 Delay determination of the default catalog/schema until schema management tool or session factory creation

This commit is contained in:
Yoann Rodière 2021-11-10 13:54:00 +01:00
parent 495bd51caa
commit 4d5306a82d
34 changed files with 314 additions and 180 deletions

View File

@ -2257,8 +2257,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
// for now we only handle id generators as ExportableProducers
final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
final String defaultCatalog = extractName( getDatabase().getDefaultNamespace().getName().getCatalog(), dialect );
final String defaultSchema = extractName( getDatabase().getDefaultNamespace().getName().getSchema(), dialect );
for ( PersistentClass entityBinding : entityBindingMap.values() ) {
if ( entityBinding.isInherited() ) {
@ -2268,8 +2266,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
handleIdentifierValueBinding(
entityBinding.getIdentifier(),
dialect,
defaultCatalog,
defaultSchema,
(RootClass) entityBinding
);
}
@ -2282,8 +2278,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
handleIdentifierValueBinding(
( (IdentifierCollection) collection ).getIdentifier(),
dialect,
defaultCatalog,
defaultSchema,
null
);
}
@ -2292,8 +2286,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
private void handleIdentifierValueBinding(
KeyValue identifierValueBinding,
Dialect dialect,
String defaultCatalog,
String defaultSchema,
RootClass entityBinding) {
// todo : store this result (back into the entity or into the KeyValue, maybe?)
// This process of instantiating the id-generator is called multiple times.
@ -2303,8 +2295,6 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
final IdentifierGenerator ig = identifierValueBinding.createIdentifierGenerator(
getIdentifierGeneratorFactory(),
dialect,
defaultCatalog,
defaultSchema,
entityBinding
);

View File

@ -436,17 +436,12 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
public MappingDefaultsImpl(StandardServiceRegistry serviceRegistry) {
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
this.implicitSchemaName = configService.getSetting(
AvailableSettings.DEFAULT_SCHEMA,
StandardConverters.STRING,
null
);
this.implicitCatalogName = configService.getSetting(
AvailableSettings.DEFAULT_CATALOG,
StandardConverters.STRING,
null
);
// AvailableSettings.DEFAULT_SCHEMA and AvailableSettings.DEFAULT_CATALOG
// are taken into account later, at runtime, when rendering table/sequence names.
// These fields are exclusively about mapping defaults,
// overridden in XML mappings or through setters in MetadataBuilder.
this.implicitSchemaName = null;
this.implicitCatalogName = null;
this.implicitlyQuoteIdentifiers = configService.getSetting(
AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS,

View File

@ -50,7 +50,6 @@ import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.id.uuid.LocalObjectUuidHelper;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.NullnessHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
@ -94,6 +93,8 @@ import static org.hibernate.cfg.AvailableSettings.CONVENTIONAL_JAVA_CONSTANTS;
import static org.hibernate.cfg.AvailableSettings.CRITERIA_VALUE_HANDLING_MODE;
import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_CATALOG;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_SCHEMA;
import static org.hibernate.cfg.AvailableSettings.DELAY_ENTITY_LOADER_CREATIONS;
import static org.hibernate.cfg.AvailableSettings.DISCARD_PC_ON_CLOSE;
import static org.hibernate.cfg.AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS;
@ -253,6 +254,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private boolean queryParametersValidationEnabled;
private ValueHandlingMode criteriaValueHandlingMode;
private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode;
// These two settings cannot be modified from the builder,
// in order to maintain consistency.
// Indeed, other components (the schema tools) also make use of these settings,
// and THOSE do not have access to session factory options.
private final String defaultCatalog;
private final String defaultSchema;
private Map<String, SqmFunctionDescriptor> sqlFunctions;
@ -576,6 +583,9 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
configurationSettings.get( IMMUTABLE_ENTITY_UPDATE_QUERY_HANDLING_MODE )
);
this.defaultCatalog = ConfigurationHelper.getString( DEFAULT_CATALOG, configurationSettings );
this.defaultSchema = ConfigurationHelper.getString( DEFAULT_SCHEMA, configurationSettings );
this.inClauseParameterPaddingEnabled = ConfigurationHelper.getBoolean(
IN_CLAUSE_PARAMETER_PADDING,
configurationSettings,
@ -1148,6 +1158,16 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return immutableEntityUpdateQueryHandlingMode;
}
@Override
public String getDefaultCatalog() {
return defaultCatalog;
}
@Override
public String getDefaultSchema() {
return defaultSchema;
}
@Override
public boolean isFailOnPaginationOverCollectionFetchEnabled() {
return this.failOnPaginationOverCollectionFetchEnabled;

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.boot.model.relational;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
@ -27,6 +28,22 @@ public interface SqlStringGenerationContext {
*/
IdentifierHelper getIdentifierHelper();
/**
* @return The default catalog, used for table/sequence names that do not explicitly mention a catalog.
* May be {@code null}.
* This default is generally applied automatically by the {@link #format(QualifiedName) format methods},
* but in some cases it can be useful to access it directly.
*/
Identifier getDefaultCatalog();
/**
* @return The default schema, used for table/sequence names that do not explicitly mention a schema.
* May be {@code null}.
* This default is generally applied automatically by the {@link #format(QualifiedName) format methods},
* but in some cases it can be useful to access it directly.
*/
Identifier getDefaultSchema();
/**
* Render a formatted a table name
*

View File

@ -6,31 +6,90 @@
*/
package org.hibernate.boot.model.relational.internal;
import java.util.Map;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.QualifiedSequenceName;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter;
public class SqlStringGenerationContextImpl
implements SqlStringGenerationContext {
/**
* @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc.
* @param database The database metadata, to retrieve the implicit namespace name configured through XML mapping.
* @param configurationMap The configuration map, holding settings such as {@link AvailableSettings#DEFAULT_SCHEMA}.
* @return An {@link SqlStringGenerationContext}.
*/
public static SqlStringGenerationContext fromConfigurationMap(JdbcEnvironment jdbcEnvironment,
Database database, Map<String, Object> configurationMap) {
String defaultCatalog = (String) configurationMap.get( AvailableSettings.DEFAULT_CATALOG );
String defaultSchema = (String) configurationMap.get( AvailableSettings.DEFAULT_SCHEMA );
return fromExplicit( jdbcEnvironment, database, defaultCatalog, defaultSchema );
}
/**
* @param jdbcEnvironment The JDBC environment, to extract the dialect, identifier helper, etc.
* @param database The database metadata, to retrieve the implicit namespace name configured through XML mapping.
* @param defaultCatalog The default catalog to use, unless an implicit catalog was configured through XML mapping.
* @param defaultSchema The default schema to use, unless an implicit schema was configured through XML mapping.
* @return An {@link SqlStringGenerationContext}.
*/
public static SqlStringGenerationContext fromExplicit(JdbcEnvironment jdbcEnvironment,
Database database, String defaultCatalog, String defaultSchema) {
Namespace.Name implicitNamespaceName = database.getDefaultNamespace().getPhysicalName();
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
NameQualifierSupport nameQualifierSupport = jdbcEnvironment.getNameQualifierSupport();
Identifier actualDefaultCatalog = null;
if ( nameQualifierSupport.supportsCatalogs() ) {
actualDefaultCatalog = implicitNamespaceName.getCatalog() != null
? implicitNamespaceName.getCatalog()
: identifierHelper.toIdentifier( defaultCatalog );
}
Identifier actualDefaultSchema = null;
if ( nameQualifierSupport.supportsSchemas() ) {
actualDefaultSchema = implicitNamespaceName.getSchema() != null
? implicitNamespaceName.getSchema()
: identifierHelper.toIdentifier( defaultSchema );
}
return new SqlStringGenerationContextImpl( jdbcEnvironment, actualDefaultCatalog, actualDefaultSchema );
}
public static SqlStringGenerationContext forTests(JdbcEnvironment jdbcEnvironment) {
return new SqlStringGenerationContextImpl( jdbcEnvironment );
return forTests( jdbcEnvironment, null, null );
}
public static SqlStringGenerationContext forTests(JdbcEnvironment jdbcEnvironment,
String defaultCatalog, String defaultSchema) {
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
return new SqlStringGenerationContextImpl( jdbcEnvironment,
identifierHelper.toIdentifier( defaultCatalog ), identifierHelper.toIdentifier( defaultSchema ) );
}
private final Dialect dialect;
private final IdentifierHelper identifierHelper;
private final QualifiedObjectNameFormatter qualifiedObjectNameFormatter;
private final Identifier defaultCatalog;
private final Identifier defaultSchema;
@SuppressWarnings("deprecation")
public SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment) {
private SqlStringGenerationContextImpl(JdbcEnvironment jdbcEnvironment,
Identifier defaultCatalog, Identifier defaultSchema) {
this.dialect = jdbcEnvironment.getDialect();
this.identifierHelper = jdbcEnvironment.getIdentifierHelper();
this.qualifiedObjectNameFormatter = jdbcEnvironment.getQualifiedObjectNameFormatter();
this.defaultCatalog = defaultCatalog;
this.defaultSchema = defaultSchema;
}
@Override
@ -43,27 +102,69 @@ public class SqlStringGenerationContextImpl
return identifierHelper;
}
@Override
public Identifier getDefaultCatalog() {
return defaultCatalog;
}
@Override
public Identifier getDefaultSchema() {
return defaultSchema;
}
@Override
public String format(QualifiedTableName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
return qualifiedObjectNameFormatter.format( withDefaults( qualifiedName ), dialect );
}
@Override
public String format(QualifiedSequenceName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
return qualifiedObjectNameFormatter.format( withDefaults( qualifiedName ), dialect );
}
@Override
public String format(QualifiedName qualifiedName) {
return qualifiedObjectNameFormatter.format( qualifiedName, dialect );
return qualifiedObjectNameFormatter.format( withDefaults( qualifiedName ), dialect );
}
private QualifiedTableName withDefaults(QualifiedTableName name) {
if ( name.getCatalogName() == null && defaultCatalog != null
|| name.getSchemaName() == null && defaultSchema != null ) {
return new QualifiedTableName( withDefault( name.getCatalogName(), defaultCatalog ),
withDefault( name.getSchemaName(), defaultSchema ), name.getTableName() );
}
return name;
}
private QualifiedSequenceName withDefaults(QualifiedSequenceName name) {
if ( name.getCatalogName() == null && defaultCatalog != null
|| name.getSchemaName() == null && defaultSchema != null ) {
return new QualifiedSequenceName( withDefault( name.getCatalogName(), defaultCatalog ),
withDefault( name.getSchemaName(), defaultSchema ), name.getSequenceName() );
}
return name;
}
private QualifiedName withDefaults(QualifiedName name) {
if ( name.getCatalogName() == null && defaultCatalog != null
|| name.getSchemaName() == null && defaultSchema != null ) {
return new QualifiedSequenceName( withDefault( name.getCatalogName(), defaultCatalog ),
withDefault( name.getSchemaName(), defaultSchema ), name.getObjectName() );
}
return name;
}
private static Identifier withDefault(Identifier value, Identifier defaultValue) {
return value != null ? value : defaultValue;
}
@Override
public String formatWithoutCatalog(QualifiedSequenceName qualifiedName) {
QualifiedSequenceName nameToFormat;
if ( qualifiedName.getCatalogName() != null ) {
if ( qualifiedName.getCatalogName() != null
|| qualifiedName.getSchemaName() == null && defaultSchema != null ) {
nameToFormat = new QualifiedSequenceName( null,
qualifiedName.getSchemaName(), qualifiedName.getSequenceName() );
withDefault( qualifiedName.getSchemaName(), defaultSchema ), qualifiedName.getSequenceName() );
}
else {
nameToFormat = qualifiedName;

View File

@ -796,17 +796,13 @@ public class ModelBinder {
// YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, objectNameNormalizer);
if ( database.getDefaultNamespace().getPhysicalName().getSchema() != null ) {
params.setProperty(
PersistentIdentifierGenerator.SCHEMA,
database.getDefaultNamespace().getPhysicalName().getSchema().render( database.getDialect() )
);
String implicitSchemaName = metadataBuildingContext.getMappingDefaults().getImplicitSchemaName();
if ( implicitSchemaName != null ) {
params.setProperty( PersistentIdentifierGenerator.SCHEMA, implicitSchemaName );
}
if ( database.getDefaultNamespace().getPhysicalName().getCatalog() != null ) {
params.setProperty(
PersistentIdentifierGenerator.CATALOG,
database.getDefaultNamespace().getPhysicalName().getCatalog().render( database.getDialect() )
);
String implicitCatalogName = metadataBuildingContext.getMappingDefaults().getImplicitCatalogName();
if ( implicitCatalogName != null ) {
params.setProperty( PersistentIdentifierGenerator.CATALOG, implicitCatalogName );
}
params.putAll( generator.getParameters() );
@ -3051,7 +3047,7 @@ public class ModelBinder {
return database.toIdentifier( tableSpecSource.getExplicitCatalogName() );
}
else {
return database.getDefaultNamespace().getName().getCatalog();
return database.toIdentifier( metadataBuildingContext.getMappingDefaults().getImplicitCatalogName() );
}
}
@ -3060,7 +3056,7 @@ public class ModelBinder {
return database.toIdentifier( tableSpecSource.getExplicitSchemaName() );
}
else {
return database.getDefaultNamespace().getName().getSchema();
return database.toIdentifier( metadataBuildingContext.getMappingDefaults().getImplicitSchemaName() );
}
}

View File

@ -420,6 +420,16 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
return delegate.getImmutableEntityUpdateQueryHandlingMode();
}
@Override
public String getDefaultCatalog() {
return delegate.getDefaultCatalog();
}
@Override
public String getDefaultSchema() {
return delegate.getDefaultSchema();
}
@Override
public boolean inClauseParameterPaddingEnabled() {
return delegate.inClauseParameterPaddingEnabled();

View File

@ -280,6 +280,26 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
return ImmutableEntityUpdateQueryHandlingMode.WARNING;
}
/**
* The default catalog to use in generated SQL when a catalog wasn't specified in the mapping,
* neither explicitly nor implicitly (see the concept of implicit catalog in XML mapping).
*
* @return The default catalog to use.
*/
default String getDefaultCatalog() {
return null;
}
/**
* The default schema to use in generated SQL when a catalog wasn't specified in the mapping,
* neither explicitly nor implicitly (see the concept of implicit schema in XML mapping).
*
* @return The default schema to use.
*/
default String getDefaultSchema() {
return null;
}
default boolean inClauseParameterPaddingEnabled() {
return false;
}

View File

@ -58,8 +58,8 @@ public final class Settings {
public Settings(SessionFactoryOptions sessionFactoryOptions, String defaultCatalogName, String defaultSchemaName) {
this.sessionFactoryOptions = sessionFactoryOptions;
this.defaultCatalogName = defaultCatalogName;
this.defaultSchemaName = defaultSchemaName;
this.defaultCatalogName = defaultCatalogName != null ? defaultCatalogName : sessionFactoryOptions.getDefaultCatalog();
this.defaultSchemaName = defaultSchemaName != null ? defaultSchemaName : sessionFactoryOptions.getDefaultSchema();
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "SessionFactory name : %s", sessionFactoryOptions.getSessionFactoryName() );

View File

@ -480,10 +480,10 @@ public class TableBinder {
String subselect,
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
schema = BinderHelper.isEmptyOrNullAnnotationValue( schema )
? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getSchema() )
? buildingContext.getBuildingOptions().getMappingDefaults().getImplicitSchemaName()
: schema;
catalog = BinderHelper.isEmptyOrNullAnnotationValue( catalog )
? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getCatalog() )
? buildingContext.getBuildingOptions().getMappingDefaults().getImplicitCatalogName()
: catalog;
final Table table;

View File

@ -59,9 +59,7 @@ public class FilterConfiguration {
}
else if ( persistentClass != null ) {
String table = persistentClass.getTable().getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
);
return Collections.singletonMap( null, table );
}

View File

@ -238,10 +238,11 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
this.uuid = options.getUuid();
jdbcServices = serviceRegistry.getService( JdbcServices.class );
sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcServices.getJdbcEnvironment() );
ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
this.properties = new HashMap<>();
this.properties.putAll( serviceRegistry.getService( ConfigurationService.class ).getSettings() );
this.properties.putAll( configurationService.getSettings() );
if ( !properties.containsKey( AvailableSettings.JPA_VALIDATION_FACTORY )
&& !properties.containsKey( AvailableSettings.JAKARTA_VALIDATION_FACTORY ) ) {
if ( getSessionFactoryOptions().getValidatorFactoryReference() != null ) {
@ -259,6 +260,10 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
maskOutSensitiveInformation(this.properties);
logIfEmptyCompositesEnabled( this.properties );
sqlStringGenerationContext = SqlStringGenerationContextImpl.fromExplicit(
jdbcServices.getJdbcEnvironment(), bootMetamodel.getDatabase(),
options.getDefaultCatalog(), options.getDefaultSchema() );
this.cacheAccess = this.serviceRegistry.getService( CacheImplementor.class );
this.jpaPersistenceUnitUtil = new PersistenceUnitUtilImpl( this );
@ -300,8 +305,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator(
bootMetamodel.getIdentifierGeneratorFactory(),
jdbcServices.getJdbcEnvironment().getDialect(),
settings.getDefaultCatalogName(),
settings.getDefaultSchemaName(),
(RootClass) model
);
generator.initialize( sqlStringGenerationContext );

View File

@ -174,7 +174,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
if ( isGenerated( dialect ) ) {
final String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema );
final String tableName = getTable().getQualifiedName( context );
return String.format(
Locale.ROOT,
"%s evictData constraint %s",
@ -197,7 +197,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
// empty string. Prevent blank "alter table" statements.
String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema );
if ( !StringHelper.isEmpty( constraintString ) ) {
final String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema );
final String tableName = getTable().getQualifiedName( context );
return dialect.getAlterTableString( tableName ) + " " + constraintString;
}
}

View File

@ -90,9 +90,7 @@ public class ForeignKey extends Constraint {
constraintName,
columnNames,
referencedTable.getQualifiedName(
context,
defaultCatalog,
defaultSchema
context
),
referencedColumnNames,
isReferenceToPrimaryKey()
@ -179,7 +177,7 @@ public class ForeignKey extends Constraint {
public String sqlDropString(SqlStringGenerationContext context,
String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
String tableName = getTable().getQualifiedName( context, defaultCatalog, defaultSchema );
String tableName = getTable().getQualifiedName( context );
final StringBuilder buf = new StringBuilder( dialect.getAlterTableString( tableName ) );
buf.append( dialect.getDropForeignKeyString() );
if ( dialect.supportsIfExistsBeforeConstraintName() ) {

View File

@ -55,7 +55,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
String name,
String defaultCatalog,
String defaultSchema) {
return buildSqlDropIndexString( name, table.getQualifiedName( context, defaultCatalog, defaultSchema ) );
return buildSqlDropIndexString( name, table.getQualifiedName( context ) );
}
public static String buildSqlDropIndexString(
@ -76,7 +76,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
return buildSqlCreateIndexString(
context.getDialect(),
name,
table.getQualifiedName( context, defaultCatalog, defaultSchema ),
table.getQualifiedName( context ),
columns,
columnOrderMap,
unique
@ -151,7 +151,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
Dialect dialect = context.getDialect();
return "drop index " +
StringHelper.qualify(
table.getQualifiedName( context, defaultCatalog, defaultSchema ),
table.getQualifiedName( context ),
getQuotedName( dialect )
);
}

View File

@ -18,6 +18,11 @@ import org.hibernate.id.factory.IdentifierGeneratorFactory;
*/
public interface KeyValue extends Value {
/**
* @deprecated Use {@link #createIdentifierGenerator(IdentifierGeneratorFactory, Dialect, RootClass)}
* instead.
*/
@Deprecated
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
@ -25,6 +30,11 @@ public interface KeyValue extends Value {
String defaultSchema,
RootClass rootClass) throws MappingException;
IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
RootClass rootClass) throws MappingException;
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect);
public void createForeignKeyOfEntity(String entityName);

View File

@ -297,6 +297,14 @@ public abstract class SimpleValue implements KeyValue {
return identifierGenerator;
}
@Override
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
RootClass rootClass) throws MappingException {
return createIdentifierGenerator( identifierGeneratorFactory, dialect, null, null, rootClass );
}
@Override
public IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
@ -310,11 +318,10 @@ public abstract class SimpleValue implements KeyValue {
}
final Properties params = new Properties();
//if the hibernate-mapping did not specify a schema/catalog, use the defaults
//specified by properties - but note that if the schema/catalog were specified
//in hibernate-mapping, or as params, they will already be initialized and
//will override the values set here (they are in identifierGeneratorProperties)
// This is for backwards compatibility only;
// when this method is called by Hibernate ORM, defaultSchema and defaultCatalog are always
// null, and defaults are handled later.
if ( defaultSchema != null ) {
params.setProperty( PersistentIdentifierGenerator.SCHEMA, defaultSchema);
}
@ -326,7 +333,6 @@ public abstract class SimpleValue implements KeyValue {
// default initial value and allocation size per-JPA defaults
params.setProperty( OptimizableGenerator.INITIAL_PARAM, String.valueOf( OptimizableGenerator.DEFAULT_INITIAL_VALUE ) );
params.setProperty( OptimizableGenerator.INCREMENT_PARAM, String.valueOf( OptimizableGenerator.DEFAULT_INCREMENT_SIZE ) );
//init the table here instead of earlier, so that we can get a quoted table name
//TODO: would it be better to simply pass the qualified table name, instead of
// splitting it up into schema/catalog/table names
@ -470,7 +476,7 @@ public abstract class SimpleValue implements KeyValue {
public boolean isConstrained() {
return !"none".equals( foreignKeyName ) && !hasFormula();
}
public String getForeignKeyDefinition() {
return foreignKeyDefinition;
}

View File

@ -27,7 +27,6 @@ import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.tool.schema.extract.spi.ColumnInformation;
import org.hibernate.tool.schema.extract.spi.TableInformation;
@ -121,18 +120,11 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
return contributor;
}
public String getQualifiedName(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
public String getQualifiedName(SqlStringGenerationContext context) {
if ( subselect != null ) {
return "( " + subselect + " )";
}
IdentifierHelper identifierHelper = context.getIdentifierHelper();
Identifier usedSchema = schema == null ?
identifierHelper.toIdentifier( defaultSchema ) :
schema;
Identifier usedCatalog = catalog == null ?
identifierHelper.toIdentifier( defaultCatalog ) :
catalog;
return context.format( new QualifiedTableName( usedCatalog, usedSchema, name ) );
return context.format( new QualifiedTableName( catalog, schema, name ) );
}
/**
@ -422,16 +414,8 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
Dialect dialect,
Metadata metadata,
TableInformation tableInfo,
Identifier defaultCatalog,
Identifier defaultSchema,
SqlStringGenerationContext sqlStringGenerationContext) throws HibernateException {
final String tableName = sqlStringGenerationContext.format(
new QualifiedTableName(
catalog != null ? catalog : defaultCatalog,
schema != null ? schema : defaultSchema,
name
)
);
final String tableName = sqlStringGenerationContext.format( new QualifiedTableName( catalog, schema, name ) );
StringBuilder root = new StringBuilder( dialect.getAlterTableString( tableName ) )
.append( ' ' )
@ -507,7 +491,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
Dialect dialect = context.getDialect();
StringBuilder buf = new StringBuilder( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
.append( ' ' )
.append( getQualifiedName( context, defaultCatalog, defaultSchema ) )
.append( getQualifiedName( context ) )
.append( " (" );
boolean identityColumn = idValue != null && idValue.isIdentityColumn( p.getIdentifierGeneratorFactory(), dialect );
@ -601,7 +585,7 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
@Override
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
return dialect.getDropTableString( getQualifiedName( context, defaultCatalog, defaultSchema ) );
return dialect.getDropTableString( getQualifiedName( context ) );
}
public PrimaryKey getPrimaryKey() {

View File

@ -515,8 +515,6 @@ public abstract class AbstractCollectionPersister
identifierGenerator = idColl.getIdentifier().createIdentifierGenerator(
creationContext.getMetadata().getIdentifierGeneratorFactory(),
factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName(),
null
);
identifierGenerator.initialize( creationContext.getSessionFactory().getSqlStringGenerationContext() );

View File

@ -23,7 +23,6 @@ import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator;
@ -479,9 +478,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
while ( iter.hasNext() ) {
Property prop = iter.next();
String tabname = prop.getValue().getTable().getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
);
propertyTableNumbers[i] = getTableId( tabname, this.tableNames );
naturalOrderPropertyTableNumbers[i] = getTableId( tabname, naturalOrderTableNames );
@ -501,9 +498,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
Property prop = iter.next();
Table tab = prop.getValue().getTable();
String tabname = tab.getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
);
Integer tabnum = getTableId( tabname, subclassTableNameClosure );
propTableNumbers.add( tabnum );
@ -549,13 +544,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
notNullColumnTableNumbers = new int[subclassSpan];
final int id = getTableId(
table.getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
),
subclassTableNameClosure
);
notNullColumnTableNumbers[subclassSpanMinusOne] = id;
factory.getSqlStringGenerationContext()
),
subclassTableNameClosure
);
notNullColumnTableNumbers[subclassSpanMinusOne] = id;
notNullColumnNames = new String[subclassSpan];
notNullColumnNames[subclassSpanMinusOne] = subclassTableKeyColumnClosure[id][0]; //( (Column) model.getTable().getPrimaryKey().getColumnIterator().next() ).getName();
}
@ -618,9 +611,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
subclassesByDiscriminatorValue.put( discriminatorValue, sc.getEntityName() );
int id = getTableId(
table.getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
),
subclassTableNameClosure
);
@ -753,9 +744,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
SessionFactoryImplementor factory) {
final String tableName = persistentClass.getTable().getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
);
associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping );
@ -764,9 +753,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
while ( itr.hasNext() ) {
final Join join = itr.next();
final String secondaryTableName = join.getTable().getQualifiedName(
factory.getSqlStringGenerationContext(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName()
factory.getSqlStringGenerationContext()
);
associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping );
}

View File

@ -29,7 +29,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.cfg.Settings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -460,9 +459,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
if ( !model.hasSubclasses() ) {
return model.getTable().getQualifiedName(
sqlStringGenerationContext,
settings.getDefaultCatalogName(),
settings.getDefaultSchemaName()
sqlStringGenerationContext
);
}
@ -506,9 +503,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
buf.append( " from " )
.append(
table.getQualifiedName(
sqlStringGenerationContext,
settings.getDefaultCatalogName(),
settings.getDefaultSchemaName()
sqlStringGenerationContext
)
);
buf.append( " union " );

View File

@ -10,6 +10,8 @@ import java.util.Map;
import java.util.regex.Pattern;
import org.hibernate.QueryException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.collection.SQLLoadableCollection;
import org.hibernate.persister.entity.SQLLoadable;
@ -71,6 +73,8 @@ public class SQLQueryParser {
final StringBuilder result = new StringBuilder( sqlQuery.length() + 20 );
int left, right;
SqlStringGenerationContext sqlStringGenerationContext = factory.getSqlStringGenerationContext();
// replace {....} with corresponding column aliases
for ( int curr = 0; curr < sqlQuery.length(); curr = right + 1 ) {
if ( ( left = sqlQuery.indexOf( '{', curr ) ) < 0 ) {
@ -94,32 +98,32 @@ public class SQLQueryParser {
// Domain replacement
switch ( aliasPath ) {
case DOMAIN_PLACEHOLDER: {
final String catalogName = factory.getSettings().getDefaultCatalogName();
final Identifier catalogName = sqlStringGenerationContext.getDefaultCatalog();
if ( catalogName != null ) {
result.append( catalogName );
result.append( catalogName.render( sqlStringGenerationContext.getDialect() ) );
result.append( "." );
}
final String schemaName = factory.getSettings().getDefaultSchemaName();
final Identifier schemaName = sqlStringGenerationContext.getDefaultSchema();
if ( schemaName != null ) {
result.append( schemaName );
result.append( schemaName.render( sqlStringGenerationContext.getDialect() ) );
result.append( "." );
}
break;
}
// Schema replacement
case SCHEMA_PLACEHOLDER: {
final String schemaName = factory.getSettings().getDefaultSchemaName();
final Identifier schemaName = sqlStringGenerationContext.getDefaultSchema();
if ( schemaName != null ) {
result.append( schemaName );
result.append( schemaName.render( sqlStringGenerationContext.getDialect() ) );
result.append( "." );
}
break;
}
// Catalog replacement
case CATALOG_PLACEHOLDER: {
final String catalogName = factory.getSettings().getDefaultCatalogName();
final Identifier catalogName = sqlStringGenerationContext.getDefaultCatalog();
if ( catalogName != null ) {
result.append( catalogName );
result.append( catalogName.render( sqlStringGenerationContext.getDialect() ) );
result.append( "." );
}
break;

View File

@ -14,6 +14,7 @@ import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedSequenceName;
import org.hibernate.boot.model.relational.QualifiedTableName;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.service.ServiceRegistry;
@ -39,16 +40,15 @@ public class DatabaseInformationImpl
public DatabaseInformationImpl(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
SqlStringGenerationContext sqlStringGenerationContext,
DdlTransactionIsolator ddlTransactionIsolator,
Namespace.Name defaultNamespace,
SchemaManagementTool tool) throws SQLException {
this.jdbcEnvironment = jdbcEnvironment;
this.extractionContext = tool.getExtractionTool().createExtractionContext(
serviceRegistry,
jdbcEnvironment,
sqlStringGenerationContext,
ddlTransactionIsolator,
defaultNamespace.getCatalog(),
defaultNamespace.getSchema(),
this
);

View File

@ -12,7 +12,6 @@ import java.sql.SQLException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.service.ServiceRegistry;
@ -27,8 +26,6 @@ public class ExtractionContextImpl implements ExtractionContext {
private final SqlStringGenerationContext sqlStringGenerationContext;
private final JdbcConnectionAccess jdbcConnectionAccess;
private final DatabaseObjectAccess registeredTableAccess;
private final Identifier defaultCatalogName;
private final Identifier defaultSchemaName;
private Connection jdbcConnection;
private DatabaseMetaData jdbcDatabaseMetaData;
@ -36,17 +33,14 @@ public class ExtractionContextImpl implements ExtractionContext {
public ExtractionContextImpl(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
SqlStringGenerationContext sqlStringGenerationContext,
JdbcConnectionAccess jdbcConnectionAccess,
DatabaseObjectAccess registeredTableAccess,
Identifier defaultCatalogName,
Identifier defaultSchemaName) {
DatabaseObjectAccess registeredTableAccess) {
this.serviceRegistry = serviceRegistry;
this.jdbcEnvironment = jdbcEnvironment;
this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment );
this.sqlStringGenerationContext = sqlStringGenerationContext;
this.jdbcConnectionAccess = jdbcConnectionAccess;
this.registeredTableAccess = registeredTableAccess;
this.defaultCatalogName = defaultCatalogName;
this.defaultSchemaName = defaultSchemaName;
}
@Override
@ -92,12 +86,12 @@ public class ExtractionContextImpl implements ExtractionContext {
@Override
public Identifier getDefaultCatalog() {
return defaultCatalogName;
return sqlStringGenerationContext.getDefaultCatalog();
}
@Override
public Identifier getDefaultSchema() {
return defaultSchemaName;
return sqlStringGenerationContext.getDefaultSchema();
}
@Override

View File

@ -28,6 +28,7 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.engine.jdbc.internal.Formatter;
import org.hibernate.internal.util.StringHelper;
@ -97,6 +98,11 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
ExecutionOptions options,
ContributableMatcher contributableInclusionFilter,
TargetDescriptor targetDescriptor) {
SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.fromConfigurationMap(
tool.getServiceRegistry().getService( JdbcEnvironment.class ),
metadata.getDatabase(),
options.getConfigurationValues()
);
if ( !targetDescriptor.getTargetTypes().isEmpty() ) {
final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() );
final DdlTransactionIsolator ddlTransactionIsolator = tool.getDdlTransactionIsolator( jdbcContext );
@ -104,7 +110,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(
tool.getServiceRegistry(),
ddlTransactionIsolator,
metadata.getDatabase().getDefaultNamespace().getName(),
sqlStringGenerationContext,
tool
);
@ -120,7 +126,8 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
}
try {
performMigration( metadata, databaseInformation, options, contributableInclusionFilter, jdbcContext.getDialect(), targets );
performMigration( metadata, databaseInformation, options, contributableInclusionFilter, jdbcContext.getDialect(),
sqlStringGenerationContext, targets );
}
finally {
for ( GenerationTarget target : targets ) {
@ -169,6 +176,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
ExecutionOptions options,
ContributableMatcher contributableInclusionFilter,
Dialect dialect,
SqlStringGenerationContext sqlStringGenerationContext,
GenerationTarget... targets) {
final boolean format = Helper.interpretFormattingEnabled( options.getConfigurationValues() );
final Formatter formatter = format ? FormatStyle.DDL.getFormatter() : FormatStyle.NONE.getFormatter();
@ -176,8 +184,6 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
final Set<String> exportIdentifiers = CollectionHelper.setOfSize( 50 );
final Database database = metadata.getDatabase();
SqlStringGenerationContext sqlStringGenerationContext =
new SqlStringGenerationContextImpl( database.getJdbcEnvironment() );
// Drop all AuxiliaryDatabaseObjects
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
@ -328,8 +334,6 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
dialect,
metadata,
tableInformation,
database.getDefaultNamespace().getPhysicalName().getCatalog(),
database.getDefaultNamespace().getPhysicalName().getSchema(),
sqlStringGenerationContext
),
formatter,

View File

@ -13,7 +13,10 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table;
@ -58,13 +61,18 @@ public abstract class AbstractSchemaValidator implements SchemaValidator {
Metadata metadata,
ExecutionOptions options,
ContributableMatcher contributableInclusionFilter) {
SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.fromConfigurationMap(
tool.getServiceRegistry().getService( JdbcEnvironment.class ),
metadata.getDatabase(),
options.getConfigurationValues()
);
final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() );
final DdlTransactionIsolator isolator = tool.getDdlTransactionIsolator( jdbcContext );
final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(
tool.getServiceRegistry(),
isolator,
metadata.getDatabase().getDefaultNamespace().getName(),
sqlStringGenerationContext,
tool
);

View File

@ -14,7 +14,7 @@ import java.sql.SQLException;
import java.util.Map;
import java.util.regex.Pattern;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@ -169,15 +169,15 @@ public class Helper {
public static DatabaseInformation buildDatabaseInformation(
ServiceRegistry serviceRegistry,
DdlTransactionIsolator ddlTransactionIsolator,
Namespace.Name defaultNamespace,
SqlStringGenerationContext sqlStringGenerationContext,
SchemaManagementTool tool) {
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
try {
return new DatabaseInformationImpl(
serviceRegistry,
jdbcEnvironment,
sqlStringGenerationContext,
ddlTransactionIsolator,
defaultNamespace,
tool
);
}

View File

@ -10,6 +10,7 @@ import java.sql.Connection;
import java.util.Map;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
@ -427,16 +428,14 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
public ExtractionContext createExtractionContext(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
SqlStringGenerationContext sqlStringGenerationContext,
DdlTransactionIsolator ddlTransactionIsolator,
Identifier defaultCatalog,
Identifier defaultSchema,
ExtractionContext.DatabaseObjectAccess databaseObjectAccess) {
return new ImprovedExtractionContextImpl(
serviceRegistry,
jdbcEnvironment,
sqlStringGenerationContext,
ddlTransactionIsolator,
defaultCatalog,
defaultSchema,
databaseObjectAccess
);
}

View File

@ -243,8 +243,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
}
final Database database = metadata.getDatabase();
SqlStringGenerationContext sqlStringGenerationContext =
new SqlStringGenerationContextImpl( database.getJdbcEnvironment() );
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.fromConfigurationMap(
jdbcEnvironment, database, options.getConfigurationValues() );
final Set<String> exportIdentifiers = CollectionHelper.setOfSize( 50 );

View File

@ -211,8 +211,8 @@ public class SchemaDropperImpl implements SchemaDropper {
Formatter formatter,
GenerationTarget... targets) {
final Database database = metadata.getDatabase();
SqlStringGenerationContext sqlStringGenerationContext =
new SqlStringGenerationContextImpl( metadata.getDatabase().getJdbcEnvironment() );
SqlStringGenerationContext sqlStringGenerationContext = SqlStringGenerationContextImpl.fromConfigurationMap(
metadata.getDatabase().getJdbcEnvironment(), database, options.getConfigurationValues());
boolean tryToDropCatalogs = false;
boolean tryToDropSchemas = false;

View File

@ -12,7 +12,6 @@ import java.sql.SQLException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.service.ServiceRegistry;
@ -26,8 +25,6 @@ public class ImprovedExtractionContextImpl implements ExtractionContext {
private final JdbcEnvironment jdbcEnvironment;
private final SqlStringGenerationContext sqlStringGenerationContext;
private final DdlTransactionIsolator ddlTransactionIsolator;
private final Identifier defaultCatalog;
private final Identifier defaultSchema;
private final DatabaseObjectAccess databaseObjectAccess;
@ -36,16 +33,13 @@ public class ImprovedExtractionContextImpl implements ExtractionContext {
public ImprovedExtractionContextImpl(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
SqlStringGenerationContext sqlStringGenerationContext,
DdlTransactionIsolator ddlTransactionIsolator,
Identifier defaultCatalog,
Identifier defaultSchema,
DatabaseObjectAccess databaseObjectAccess) {
this.serviceRegistry = serviceRegistry;
this.jdbcEnvironment = jdbcEnvironment;
this.sqlStringGenerationContext = new SqlStringGenerationContextImpl( jdbcEnvironment );
this.sqlStringGenerationContext = sqlStringGenerationContext;
this.ddlTransactionIsolator = ddlTransactionIsolator;
this.defaultCatalog = defaultCatalog;
this.defaultSchema = defaultSchema;
this.databaseObjectAccess = databaseObjectAccess;
}
@ -87,12 +81,12 @@ public class ImprovedExtractionContextImpl implements ExtractionContext {
@Override
public Identifier getDefaultCatalog() {
return defaultCatalog;
return sqlStringGenerationContext.getDefaultCatalog();
}
@Override
public Identifier getDefaultSchema() {
return defaultSchema;
return sqlStringGenerationContext.getDefaultSchema();
}
@Override

View File

@ -8,6 +8,7 @@ package org.hibernate.tool.schema.spi;
import org.hibernate.Incubating;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.service.ServiceRegistry;
@ -26,9 +27,8 @@ public interface ExtractionTool {
ExtractionContext createExtractionContext(
ServiceRegistry serviceRegistry,
JdbcEnvironment jdbcEnvironment,
SqlStringGenerationContext sqlStringGenerationContext,
DdlTransactionIsolator ddlTransactionIsolator,
Identifier defaultCatalog,
Identifier defaultSchema,
ExtractionContext.DatabaseObjectAccess databaseObjectAccess);
InformationExtractor createInformationExtractor(ExtractionContext extractionContext);

View File

@ -11,13 +11,14 @@ import java.sql.SQLException;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl;
@ -25,7 +26,6 @@ import org.hibernate.tool.schema.extract.internal.ExtractionContextImpl;
import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl;
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl;
import org.hibernate.tool.schema.internal.exec.JdbcContext;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
@ -121,21 +121,23 @@ public class TestExtraPhysicalTableTypes {
throws SQLException {
Database database = metadata.getDatabase();
SqlStringGenerationContext sqlStringGenerationContext =
SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() );
DatabaseInformation dbInfo = new DatabaseInformationImpl(
ssr,
database.getJdbcEnvironment(),
sqlStringGenerationContext,
ddlTransactionIsolator,
database.getDefaultNamespace().getName(),
database.getServiceRegistry().getService( SchemaManagementTool.class )
);
ExtractionContextImpl extractionContext = new ExtractionContextImpl(
ssr,
database.getJdbcEnvironment(),
sqlStringGenerationContext,
ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(),
(ExtractionContext.DatabaseObjectAccess) dbInfo,
database.getDefaultNamespace().getPhysicalName().getCatalog(),
database.getDefaultNamespace().getPhysicalName().getSchema()
(ExtractionContext.DatabaseObjectAccess) dbInfo
);
return new InformationExtractorJdbcDatabaseMetaDataImplTest(

View File

@ -81,7 +81,7 @@ public class SchemaUpdateTableBackedSequenceTest extends BaseUnitTestCase {
// lets make sure the InitCommand is there
assertEquals( 1, database.getDefaultNamespace().getTables().size() );
Table table = database.getDefaultNamespace().getTables().iterator().next();
SqlStringGenerationContext context = SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() );
SqlStringGenerationContext context = SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment(), null, null );
assertEquals( 1, table.getInitCommands( context ).size() );
final TargetImpl target = new TargetImpl();