-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-13843: make schema migration faster #3222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Hibernate, Relational Persistence for Idiomatic Java | ||
| * | ||
| * License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
| * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
| */ | ||
| package org.hibernate.tool.schema.extract.internal; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| import org.hibernate.boot.model.relational.Namespace; | ||
| import org.hibernate.boot.model.relational.QualifiedTableName; | ||
| import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; | ||
| import org.hibernate.resource.transaction.spi.DdlTransactionIsolator; | ||
| import org.hibernate.service.ServiceRegistry; | ||
| import org.hibernate.tool.schema.extract.spi.NameSpaceTablesInformation; | ||
| import org.hibernate.tool.schema.extract.spi.TableInformation; | ||
|
|
||
| /** | ||
| * Will cache all database information by reading the tableinformation from the name space in one call. | ||
| * Schema migration becomes much faster when this object is used. | ||
| * NOTE: superclass already caches the sequence information, so perhaps cache can also be coded in superlcass | ||
| * @author francois | ||
| */ | ||
| public class DatabaseInformationCachedImpl extends DatabaseInformationImpl { | ||
| private NameSpaceTablesInformation defaultNameSpaceTablesInformation = null; | ||
| private final Namespace defaultNamespace; | ||
|
|
||
| /** | ||
| * | ||
| * @param serviceRegistry ServiceRegistry | ||
| * @param jdbcEnvironment JdbcEnvironment | ||
| * @param ddlTransactionIsolator DdlTransactionIsolator | ||
| * @param defaultNamespace NameSpace | ||
| */ | ||
| public DatabaseInformationCachedImpl( | ||
| ServiceRegistry serviceRegistry, | ||
| JdbcEnvironment jdbcEnvironment, | ||
| DdlTransactionIsolator ddlTransactionIsolator, Namespace defaultNamespace) | ||
| throws SQLException { | ||
| super(serviceRegistry, jdbcEnvironment, ddlTransactionIsolator, defaultNamespace.getName()); | ||
| this.defaultNamespace = defaultNamespace; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hibernate has specific code style, especially we use empty char aggressively. We have a ide style repo even: https://github.com/hibernate/hibernate-ide-codestyles. You might need to refer to existing code for the style issue, especially you need to insert more space chars. |
||
| } | ||
|
|
||
| @Override | ||
| public TableInformation getTableInformation(QualifiedTableName qualifiedTableName) { | ||
|
|
||
| if (defaultNameSpaceTablesInformation == null) { | ||
| // Load table information from the whole space in one go (expected to be used in case of schemaMigration, so (almost) all | ||
| // tables are likely to be retrieved) | ||
| defaultNameSpaceTablesInformation = getTablesInformation(defaultNamespace); | ||
| } | ||
| TableInformation tableInformation = defaultNameSpaceTablesInformation.getTableInformation(qualifiedTableName.getTableName().getText()); | ||
| if (tableInformation != null) { | ||
| return tableInformation; | ||
| } | ||
| return super.getTableInformation(qualifiedTableName); // result of this call can of course also be cached, does not seem to be in scope now | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,11 +93,7 @@ public void doMigration(Metadata metadata, ExecutionOptions options, TargetDescr | |
| final JdbcContext jdbcContext = tool.resolveJdbcContext( options.getConfigurationValues() ); | ||
| final DdlTransactionIsolator ddlTransactionIsolator = tool.getDdlTransactionIsolator( jdbcContext ); | ||
| try { | ||
| final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation( | ||
| tool.getServiceRegistry(), | ||
| ddlTransactionIsolator, | ||
| metadata.getDatabase().getDefaultNamespace().getName() | ||
| ); | ||
| final DatabaseInformation databaseInformation = getDatabaseInformation(ddlTransactionIsolator, metadata.getDatabase().getDefaultNamespace()); | ||
|
|
||
| final GenerationTarget[] targets = tool.buildGenerationTargets( | ||
| targetDescriptor, | ||
|
|
@@ -139,6 +135,8 @@ public void doMigration(Metadata metadata, ExecutionOptions options, TargetDescr | |
| } | ||
| } | ||
|
|
||
| protected abstract DatabaseInformation getDatabaseInformation(DdlTransactionIsolator ddlTransactionIsolator, Namespace namespace); | ||
|
||
|
|
||
| protected abstract NameSpaceTablesInformation performTablesMigration( | ||
| Metadata metadata, | ||
| DatabaseInformation existingDatabase, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure we don't need to set
nullabove. It has been set during object creation by JVM already.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed