-
-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...c/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationCachedImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 superclass | ||
* @author francois | ||
*/ | ||
public class DatabaseInformationCachedImpl extends DatabaseInformationImpl { | ||
private NameSpaceTablesInformation defaultNameSpaceTablesInformation; | ||
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; | ||
} | ||
|
||
@Override | ||
public TableInformation getTableInformation(QualifiedTableName qualifiedTableName) { | ||
if (defaultNameSpaceTablesInformation == null) { | ||
// Load table information from the whole namespace 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 | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.