-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use RDBMS specific queries updating session attributes #1481
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
Conversation
97d9b7a
to
96577e6
Compare
96577e6
to
84c3c79
Compare
Thanks for the PR @candrews but I'm not keen to add this kind of complexity to JDBC repo. I've got strong preference for sticking with standard SQL here. For advanced use cases there's an option of customizing SQL, which you already do. Besides complexity, having custom SQL OOTB is just too risky testing-wise as we cannot test all the databases - for instance, while we do have an integration test for Oracle, we cannot run it as a part of our build due to restrictions around Oracle JDBC driver. Also note that this is only a workaround for #1213 because as explained in that issue the core problem lies in how sessions are consumed. As such, it doesn't really justify the complexity presented here. |
Which is why I've written this PR so that it falls back to the current behavior for all other databases. For example, H2 falls back to the basic
I don't agree that this is a workaround - this is the solution. Applications create attributes and they expect that to work (just see #1213 for users that agree with my perspective); currently, Spring Session doesn't always work. Asking all applications to change their implementation (in a complex way) isn't great - it's much better to have Spring Session JDBC support the approach that applications already take and meet the exceptions they already in alignment with other session implementations (including every application server and other Spring Session implementations). Could you please reconsider? |
Indeed I used term SQL standard to refer to widely adopted level of SQL standard, sorry for the confusion there. Schema scripts are not really in the same ballpark, as they're not truly normative but rather simply provided for convenience/guidance.
I understand that, but it adds complexity that we really don't want to deal with in Spring Session. I'm sure there are other users with their own cases for database specific SQL in other places so if we add such behavior in one place, there will surely be requests for other places as well. There's simply isn't any pressing need to add this complexity, as customization of SQL is already possible. I agree that it isn't ideal since it requires you to manually declare For the most optimal solution to leverage capabilities of your RDBMS, I'd recommend going custom
I'm afraid anything manual is just to risky. Regarding DB2, I've just added integration tests yesterday.
We'll have to disagree there, because as explained in #1213, the original problem is that concurrent requests operate on the same attribute overwriting each other - his just makes the request that lost race condition (and threw an exception) to win the race condition. To summarize:
|
That is bad.... but maybe it can be made a bit better. |
Thanks for the offer @candrews, but again that kind of complexity is what we'd like to avoid. |
* other databases. | ||
*/ | ||
// @formatter:off | ||
private static final String CREATE_SESSION_ATTRIBUTE_QUERY_MERGE = "MERGE INTO %TABLE_NAME%_ATTRIBUTES x " |
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've got a "bad SQL grammar" exception on Oracle 18c if the SQL query has an ending semicolon.
(Yes, I know it's a declined PR, but we're using this as a workaround until the final solution.)
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.
Since this PR was declined, GitHub doesn't seem to be updating it when I push to the branch for it.
I had fixed this a while ago in my branch, so I suggest you grab it from there: https://github.com/candrews/spring-session/tree/attributes-duplicate-key
Inserting new attributes for the same session can result in a duplicate key exceptions. Using RDMS specific upsert queries solves this problem.
Resolves: #1213