Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static SourceType interpret(Object value, SourceType defaultValue) {
if ( name.isEmpty() ) {
return METADATA;
}
for ( SourceType sourceType: values() ) {
for ( var sourceType: values() ) {
if ( sourceType.toString().equalsIgnoreCase(name) ) {
return sourceType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static UniqueConstraintSchemaUpdateStrategy interpret(Object setting) {
}

try {
final UniqueConstraintSchemaUpdateStrategy byName = byName( setting.toString() );
final var byName = byName( setting.toString() );
if ( byName != null ) {
return byName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,12 +1024,12 @@ protected NameSpacePrimaryKeysInformation extractNameSpacePrimaryKeysInformation
final String currentPkName = resultSet.getString( getResultSetPrimaryKeyNameLabel() );
final Identifier currentPrimaryKeyIdentifier =
currentPkName == null ? null : toIdentifier( currentPkName );
final TableInformation tableInformation = getTableInformation(
final var tableInformation = getTableInformation(
resultSet.getString( getResultSetPrimaryKeyCatalogLabel() ),
resultSet.getString( getResultSetPrimaryKeySchemaLabel() ),
currentTableName
);
PrimaryKeyInformation primaryKeyInformation =
var primaryKeyInformation =
primaryKeysInformation.getPrimaryKeyInformation( currentTableName );
final List<ColumnInformation> columns;
if ( primaryKeyInformation != null ) {
Expand Down Expand Up @@ -1162,7 +1162,7 @@ public Iterable<IndexInformation> getIndexes(TableInformation tableInformation)
!= DatabaseMetaData.tableIndexStatistic ) {
final Identifier indexIdentifier =
toIdentifier( resultSet.getString( getResultSetIndexNameLabel() ) );
var builder = indexInformationBuilder( builders, indexIdentifier );
final var builder = indexInformationBuilder( builders, indexIdentifier );
final Identifier columnIdentifier =
toIdentifier( resultSet.getString( getResultSetColumnNameLabel() ) );
final var columnInformation = tableInformation.getColumn( columnIdentifier );
Expand Down Expand Up @@ -1199,12 +1199,15 @@ public Iterable<IndexInformation> getIndexes(TableInformation tableInformation)
private static IndexInformationImpl.Builder indexInformationBuilder(
Map<Identifier, IndexInformationImpl.Builder> builders,
Identifier indexIdentifier) {
var builder = builders.get( indexIdentifier );
final var builder = builders.get( indexIdentifier );
if ( builder == null ) {
builder = IndexInformationImpl.builder( indexIdentifier );
builders.put( indexIdentifier, builder );
final var newBuilder = IndexInformationImpl.builder( indexIdentifier );
builders.put( indexIdentifier, newBuilder );
return newBuilder;
}
else {
return builder;
}
return builder;
}

@Override
Expand Down Expand Up @@ -1238,7 +1241,7 @@ protected NameSpaceIndexesInformation extractNameSpaceIndexesInformation(ResultS
while ( resultSet.next() ) {
if ( resultSet.getShort( getResultSetIndexTypeLabel() )
!= DatabaseMetaData.tableIndexStatistic ) {
final TableInformation tableInformation = getTableInformation(
final var tableInformation = getTableInformation(
resultSet.getString( getResultSetCatalogLabel() ),
resultSet.getString( getResultSetSchemaLabel() ),
resultSet.getString( getResultSetTableNameLabel() )
Expand Down Expand Up @@ -1266,10 +1269,10 @@ private IndexInformation getOrCreateIndexInformation(
NameSpaceIndexesInformation indexesInformation,
Identifier indexIdentifier,
TableInformation tableInformation) {
final List<IndexInformation> indexes =
final var indexes =
indexesInformation.getIndexesInformation( tableInformation.getName().getTableName().getText() );
if ( indexes != null ) {
for ( IndexInformation index : indexes ) {
for ( var index : indexes ) {
if ( indexIdentifier.equals( index.getIndexIdentifier() ) ) {
return index;
}
Expand Down Expand Up @@ -1515,7 +1518,7 @@ protected NameSpaceForeignKeysInformation extractNameSpaceForeignKeysInformation
final var foreignKeysInformation = new NameSpaceForeignKeysInformation( getIdentifierHelper() );

while ( resultSet.next() ) {
final TableInformation tableInformation = getTableInformation(
final var tableInformation = getTableInformation(
resultSet.getString( getResultSetForeignKeyCatalogLabel() ),
resultSet.getString( getResultSetForeignKeySchemaLabel() ),
resultSet.getString( getResultSetForeignKeyTableLabel() )
Expand Down Expand Up @@ -1550,10 +1553,10 @@ private ForeignKeyInformation getOrCreateForeignKeyInformation(
NameSpaceForeignKeysInformation foreignKeysInformation,
Identifier foreignKeyIdentifier,
TableInformation tableInformation) {
final List<ForeignKeyInformation> foreignKeys =
final var foreignKeys =
foreignKeysInformation.getForeignKeysInformation( tableInformation.getName().getTableName().getText() );
if ( foreignKeys != null ) {
for ( ForeignKeyInformation foreignKey : foreignKeys ) {
for ( var foreignKey : foreignKeys ) {
if ( foreignKeyIdentifier.equals( foreignKey.getForeignKeyIdentifier() ) ) {
return foreignKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize;
import static org.hibernate.tool.schema.UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY;
import static org.hibernate.tool.schema.UniqueConstraintSchemaUpdateStrategy.SKIP;
import static org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation;
import static org.hibernate.tool.schema.internal.Helper.interpretFormattingEnabled;
import static org.hibernate.tool.schema.internal.SchemaCreatorImpl.createUserDefinedTypes;
import static org.hibernate.tool.schema.internal.SchemaDropperImpl.dropUserDefinedTypes;
Expand Down Expand Up @@ -520,8 +519,8 @@ protected void createSchemaAndCatalog(
SqlStringGenerationContext context,
GenerationTarget[] targets) {
if ( tryToCreateCatalogs || tryToCreateSchemas ) {
Namespace.Name logicalName = namespace.getName();
Namespace.Name physicalName = namespace.getPhysicalName();
final var logicalName = namespace.getName();
final var physicalName = namespace.getPhysicalName();

if ( tryToCreateCatalogs ) {
final Identifier catalogLogicalName = logicalName.catalog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void applyImportSources(
Dialect dialect,
GenerationTarget... targets) {
final var formatter = getImportScriptFormatter(format);
boolean hasDefaultImportFileScriptBeenExecuted = applyImportScript(
final boolean hasDefaultImportFileScriptBeenExecuted = applyImportScript(
options,
commandExtractor,
dialect,
Expand Down Expand Up @@ -123,8 +123,11 @@ private boolean containsDefaultImportFile(ScriptSourceInput importScriptInput,Ex
return false;
}
else {
final URL defaultImportFileUrl = getClassLoaderService().locateResource( DEFAULT_IMPORT_FILE );
return defaultImportFileUrl != null && importScriptInput.containsScript( defaultImportFileUrl );
final URL defaultImportFileUrl =
getClassLoaderService()
.locateResource( DEFAULT_IMPORT_FILE );
return defaultImportFileUrl != null
&& importScriptInput.containsScript( defaultImportFileUrl );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ public static ScriptSourceInput interpretScriptSourceSetting(
else {
final String scriptSourceSettingString = scriptSourceSetting.toString();
CORE_LOGGER.attemptingToResolveScriptSourceSetting( scriptSourceSettingString );
final String[] paths = splitAtCommas( scriptSourceSettingString );
final var paths = splitAtCommas( scriptSourceSettingString );
if ( paths.length == 1 ) {
return interpretScriptSourceSetting( scriptSourceSettingString, classLoaderService, charsetName );
}
final var inputs = new AbstractScriptSourceInput[paths.length];
for ( int i = 0; i < paths.length; i++ ) {
inputs[i] = interpretScriptSourceSetting( paths[i], classLoaderService, charsetName ) ;
else {
final var inputs = new AbstractScriptSourceInput[paths.length];
for ( int i = 0; i < paths.length; i++ ) {
inputs[i] = interpretScriptSourceSetting( paths[i], classLoaderService, charsetName );
}
return new ScriptSourceInputAggregate( inputs );
}
return new ScriptSourceInputAggregate( inputs );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.SourceType;
import org.hibernate.tool.schema.spi.GenerationTarget;
import org.hibernate.tool.schema.internal.exec.JdbcContext;
import org.hibernate.tool.schema.spi.ContributableMatcher;
import org.hibernate.tool.schema.spi.ExceptionHandler;
import org.hibernate.tool.schema.spi.ExecutionOptions;
Expand Down Expand Up @@ -94,7 +93,7 @@ public void doCreation(
TargetDescriptor targetDescriptor) {
if ( !targetDescriptor.getTargetTypes().isEmpty() ) {
final var configuration = options.getConfigurationValues();
final JdbcContext jdbcContext = tool.resolveJdbcContext( configuration );
final var jdbcContext = tool.resolveJdbcContext( configuration );
doCreation(
metadata,
jdbcContext.getDialect(),
Expand Down Expand Up @@ -505,8 +504,9 @@ private static void createSchemasAndCatalogs(
Formatter formatter,
SqlStringGenerationContext context,
GenerationTarget[] targets) {
final boolean tryToCreateCatalogs = options.shouldManageNamespaces() && dialect.canCreateCatalog();
final boolean tryToCreateSchemas = options.shouldManageNamespaces() && dialect.canCreateSchema();
final boolean manageNamespaces = options.shouldManageNamespaces();
final boolean tryToCreateCatalogs = manageNamespaces && dialect.canCreateCatalog();
final boolean tryToCreateSchemas = manageNamespaces && dialect.canCreateSchema();
// first, create each catalog/schema
if ( tryToCreateCatalogs || tryToCreateSchemas ) {
Set<Identifier> exportedCatalogs = new HashSet<>();
Expand Down Expand Up @@ -560,35 +560,35 @@ private static void checkExportIdentifier(Exportable exportable, Set<String> exp
*
* @return The generation commands
*/
@Internal
public List<String> generateCreationCommands(Metadata metadata, final boolean manageNamespaces) {
final var target = new JournalingGenerationTarget();

final var metadataImplementor = (MetadataImplementor) metadata;
final var dialect =
createFromMetadata(
metadata,
new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return manageNamespaces;
}

@Override
public Map<String,Object> getConfigurationValues() {
return Collections.emptyMap();
}

@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE;
}
},
metadataImplementor.getMetadataBuildingOptions()
.getServiceRegistry()
.requireService( JdbcEnvironment.class )
.getDialect();

final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return manageNamespaces;
}

@Override
public Map<String,Object> getConfigurationValues() {
return Collections.emptyMap();
}

@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE;
}
};

createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );

.getDialect(),
FormatStyle.NONE.getFormatter(),
target
);
return target.commands;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void doDrop(
TargetDescriptor targetDescriptor) {
if ( !targetDescriptor.getTargetTypes().isEmpty() ) {
final var configuration = options.getConfigurationValues();
final JdbcContext jdbcContext = tool.resolveJdbcContext( configuration );
final var jdbcContext = tool.resolveJdbcContext( configuration );
doDrop(
metadata,
options,
Expand Down Expand Up @@ -417,14 +417,15 @@ private static void dropSchemasAndCatalogs(
Formatter formatter,
SqlStringGenerationContext context,
GenerationTarget[] targets) {
boolean tryToDropCatalogs = options.shouldManageNamespaces() && dialect.canCreateCatalog();
boolean tryToDropSchemas = options.shouldManageNamespaces() && dialect.canCreateSchema();
final boolean manageNamespaces = options.shouldManageNamespaces();
final boolean tryToDropCatalogs = manageNamespaces && dialect.canCreateCatalog();
final boolean tryToDropSchemas = manageNamespaces && dialect.canCreateSchema();
if ( tryToDropCatalogs || tryToDropSchemas) {
final Set<Identifier> exportedCatalogs = new HashSet<>();
for ( var namespace : metadata.getDatabase().getNamespaces() ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
Namespace.Name logicalName = namespace.getName();
Namespace.Name physicalName = namespace.getPhysicalName();
final var logicalName = namespace.getName();
final var physicalName = namespace.getPhysicalName();

if ( tryToDropSchemas ) {
final Identifier schemaPhysicalName = context.schemaWithDefault( physicalName.schema() );
Expand All @@ -434,7 +435,7 @@ private static void dropSchemasAndCatalogs(
}
}

if (tryToDropCatalogs) {
if ( tryToDropCatalogs ) {
final Identifier catalogLogicalName = logicalName.catalog();
final Identifier catalogPhysicalName = context.catalogWithDefault( physicalName.catalog() );
if ( catalogPhysicalName != null && !exportedCatalogs.contains( catalogLogicalName ) ) {
Expand Down Expand Up @@ -495,8 +496,8 @@ public DelayedDropAction buildDelayedAction(
ExecutionOptions options,
ContributableMatcher inclusionFilter,
SourceDescriptor sourceDescriptor) {
final JournalingGenerationTarget target = new JournalingGenerationTarget();
final Dialect dialect = tool.getServiceRegistry().requireService( JdbcEnvironment.class ).getDialect();
final var target = new JournalingGenerationTarget();
final var dialect = tool.getServiceRegistry().requireService( JdbcEnvironment.class ).getDialect();
doDrop( metadata, options, inclusionFilter, dialect, sourceDescriptor, target );
return new DelayedDropActionImpl( target.commands, tool.getCustomDatabaseGenerationTarget() );
}
Expand All @@ -520,18 +521,18 @@ public void doDrop(Metadata metadata, boolean manageNamespaces, GenerationTarget
/**
* For tests
*/
@Internal
public void doDrop(
Metadata metadata,
final ServiceRegistry serviceRegistry,
final Map<String,Object> settings,
final boolean manageNamespaces,
GenerationTarget... targets) {
if ( targets == null || targets.length == 0 ) {
final var jdbcContext = tool.resolveJdbcContext( settings );
targets = new GenerationTarget[] {
new GenerationTargetToDatabase(
serviceRegistry.requireService( TransactionCoordinatorBuilder.class )
.buildDdlTransactionIsolator( jdbcContext ),
.buildDdlTransactionIsolator( tool.resolveJdbcContext( settings ) ),
true
)
};
Expand Down Expand Up @@ -603,12 +604,10 @@ public DelayedDropActionImpl(ArrayList<String> commands, GenerationTarget target
public void perform(ServiceRegistry serviceRegistry) {
CORE_LOGGER.startingDelayedSchemaDrop();

final var jdbcContext = new JdbcContextDelayedDropImpl( serviceRegistry );

if ( target == null ) {
target = new GenerationTargetToDatabase(
serviceRegistry.requireService( TransactionCoordinatorBuilder.class )
.buildDdlTransactionIsolator( jdbcContext ),
.buildDdlTransactionIsolator( new JdbcContextDelayedDropImpl( serviceRegistry ) ),
true
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void process(
final ServiceRegistry serviceRegistry,
final Map<String,Object> configuration,
DelayedDropRegistry delayedDropRegistry) {
final Set<ActionGrouping> groupings = ActionGrouping.interpret( metadata, configuration );
final var groupings = ActionGrouping.interpret( metadata, configuration );
if ( groupings.isEmpty() ) {
// no actions specified
LOG.debug( "No schema management actions found" );
Expand Down