Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

METAMODEL-86: Allow transactional querying in JDBC update scripts #164

Closed
wants to merge 3 commits into from
Closed

METAMODEL-86: Allow transactional querying in JDBC update scripts #164

wants to merge 3 commits into from

Conversation

kaspersorensen
Copy link
Contributor

Here's my attempt at solving METAMODEL-86. I wasn't sure how to test it so ... It's not really tested, except existing tests should pass obviously. Review accordingly, please :-)

@kaspersorensen
Copy link
Contributor Author

Update: I found a way to unit test this and a good thing I did too. The approach I had built wasn't really working since the query method I used closed connection. That's fixed now. Furthermore the unit test revealed that such update scripts can easily cause deadlocks at the DB level. These will be rolled back, but the client needs a good way to catch them, which is why I added the RolledBackUpdateException.

return (JdbcDataContext) super.getDataContext();
public final DataContext getDataContext() {
final Connection connection = getConnection();
return new JdbcUpdateCallbackDataContext(getJdbcDataContext(), connection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this hack took me a while before I got the idea :-) Clever trick how to make the associated DataContext use our connection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever good or clever bad? :-) Are we good to merge you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fine I think, it was just neutral observation ;-)

@jakubneubauer
Copy link
Contributor

Now I checked the rest. Also executed few tests on real database:

  • The connection obtained from the UpdateScript used for queries is the same as used for updates - OK
  • Transaction is not committed during the UpdateScript duration nor after updates/inserts/deletes nor after the queries.
  • On the other getting connection on DataContext outside of UpdateScript returns new connection - OK
  • Throwing any exception from the update script causes rollback.

Code looks fine, I recommend merge :-)

@asfgit asfgit closed this in 1d56a9f Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants