-
Notifications
You must be signed in to change notification settings - Fork 92
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
[536] [913] [910] SchemaMigrator/SchemaValidator support for PostgreSQL and CockroachDB #903
Conversation
I will convert this to a draft, it contains changes to the |
.thenAccept( result -> | ||
context.assertEquals( | ||
result, | ||
"CREATE UNIQUE INDEX aanother_pkey ON public.aanother USING btree (id)" |
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.
Not critical, but when using context.equals(expected, actual)
, the firs value is the expected one and the second the actual one.
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 normally do it that way, I don't know why I didn't in this test. I'll change it.
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.
@@ -50,6 +50,7 @@ | |||
CompletionStage<Result> select(String sql); | |||
CompletionStage<Result> select(String sql, Object[] paramValues); | |||
CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues); | |||
CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues); |
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.
Could you remind us why you need the additional method?
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.
@DavideD , since SchemaMigrator
executes select queries on system tables and executes DDL statements (which update system tables), I assumed that these queries should be executed outside of a transaction (i.e., with autocommit=true
). IIUC, this would help avoid contention with other work the DB is doing on schemas used by various applications.
If you look at the corresponding ORM code in GenerationTargetToDatabase, you can see that the statement is created using a connection obtained from a DdlTransactionIsolator
.
Javadoc for DdlTransactionIsolator
says:
* Provides access to a Connection that is isolated from
* any "current transaction" with the designed purpose of
* performing DDL commands
If you look at the DdlTransactionIsolator
implementations, you will see that autocommit
is set to true
on the Connection
that is obtained:
DdlTransactionIsolatorJtaImpl
DdlTransactionIsolatorNonJtaImpl
DdlTransactionIsolatorProvidedConnectionImpl
relies on JdbcConnectionAccessProvidedConnectionImpl
which sets autocommit
to true
I didn't see any other way to execute a query outside of a transaction that returned a CompletionStage<ResultSet>
, so I created a new method.
Is there some other method that should be used instead?
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 don't think we had this requirement before. I don't see any problem adding a new method.
But I mainly wanted a bit of an explanation written somewhere so that others know as well (maybe it wasn't obvious only to me though ;-)
At some point, we will need to add some javadoc to that class. Anyway, not something you need to worry about at the moment.
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.
Yes, I know this stuff is lacking in documentation. I will be adding that.
I have not tested it but the code looks great! Thanks @gbadner (The only very minor comment I have is I would prefer that SQL keywords were in lowercase like the rest of the SQL we generate.) |
@DavideD, thanks for doing making it a draft. I thought I defined it as a draft when I created it, but maybe I missed that. |
Thanks @gavinking!
That's fine. I can change that. |
I'm currently using the Hibernate ORM codestyle. Which of the codestyles do you use for Hibernate Reactive? |
I finally got around to taking a good look at what else needs to be done for |
@gavinking, I added a new commit that changes SQL keywords to lower-case. |
Thanks, @gbadner |
no problem
Yes, that's what we should use. Thanks. Although, our build doesn't check the code style (except of a couple of basic rules) so you might find that we are a bit inconsistent sometimes. |
b85b05f
to
7552fa8
Compare
@DavideD, I just pushed a commit that adds Javadoc and a couple of small tweaks. I forgot that I had already pushed a commit for encapsulating methods into Sanne is still looking at the ORM PR. I think this PR is ready to review, although we will obviously have to wait for the ORM PR to be finalized. Unless I hear of any required changes to this PR, I will start work on adding support for MySQL. |
hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java
Show resolved
Hide resolved
This all looks very nice, @gbadner! |
Thanks @gavinking, I'm pretty happy with it. |
...main/java/org/hibernate/reactive/provider/service/ReactiveImprovedExtractionContextImpl.java
Show resolved
Hide resolved
...hibernate/reactive/provider/service/AbstractReactiveInformationSchemaBasedExtractorImpl.java
Outdated
Show resolved
Hide resolved
I just added a commit to deal with a non-standard information_schema.columns column name used by PostgreSQL. |
Merged commits from #940. |
Great. |
@@ -124,17 +126,17 @@ protected Configuration constructConfiguration() { | |||
doneTablespace = true; | |||
} | |||
//Use JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true' | |||
configuration.setProperty( Settings.SHOW_SQL, System.getProperty(Settings.SHOW_SQL, "false") ); | |||
configuration.setProperty( Settings.SHOW_SQL, System.getProperty(Settings.SHOW_SQL, "true") ); |
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.
@gbadner could you roll back this change please?
P.S. A more convenient way to enable SQL logging during development is to set:
logger.hibernate.level = debug
in log4j.properties
.
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.
@gavinking, this is done.
Is this the only thing blocking us from merging this? |
We should no longer test with Hibernate ORM 5.5 since this requires those changes which are exclusively in 5.6 |
P.S. I've already upgraded Quarkus to use ORM |
Yes, I agree. |
So am I understanding correctly that as of this change, we now have two redundant runs of the test suite for every CI build? |
Anyway, OK, right, @gbadner, this seemed to fix it: |
I pushed a commit that disables SQL logging and includes @gavinking 's commit to fix DI. Crossing my fingers that everything passes... |
Hurray, all passed! |
WDYT shall we merge it? |
@gavinking, yes, please do! |
It's still a "Draft" :) |
Oops, it's "Open" now. |
There's a lot of commits here, should we squash? |
Sure, I'll squash and push to my branch... |
[536] Correct order of arguments to TestContext#assertEquals [536] : Change SQL keywords to lowercase [536] Encapsulate extraction methods into ReactiveExtractionTool [536] : Added Javodoc, made minor changes to sych up with ORM, changed more SQL keywords that were upper-case to lower-case [536] : Use org.hibernate.reactive.pool.impl.Parameters#process for dialect-specific parameter placeholders [536] : Add a method for non-standard information_schema.columns column name used by PostgreSQL [536] Change `ResultSetAdapter#getLong(String)` to be convert String to Long [536] Change `ResultSetAdapter#getLong(String)` to throw the original exception if the value is neither a long nor a String that can be parsed as a long. [913] SchemaMigrator/SchemaValidator support for CockroachDB [536] [913] Comment out settings in gradle.properties [910] SchemaMigrator/SchemaValidator support for MySQL [910] Fix off-by-one bug in ResultSetAdaptor#getXXX(int columnIndex) methods [910] SchemaMigrator/SchemaValidator support for MariaDB [910] Improve Javadoc; simplify MySqlReactiveInformationExtractorImpl methods [536] Disable SQL logging attempt to fix CI build
ee87282
to
0223cb4
Compare
Excellent! Fantastic to finally have this done! Thanks @gbadner |
Nice! |
For #536, #913, and #910 .
Requires ORM PR:
hibernate/hibernate-orm#4106