-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Support batches using @SqlUpdate #844
Comments
If there is agreement, I can prototype the simple version. |
I think that's an interesting idea! Definitely would give a prototype a spin. |
I started hacking on this and it turns out to be rather complicated since it doesn't fit the existing model at all. |
@electrum Could you elaborate? |
This is the API and test I started with: https://gist.github.com/electrum/5b08813442be8b2d348293ce0ddd2423 The extension model is based on a method annotation mapping to a I need to play around with this more. It might turn out easier than I thought. Though I won't have time to look at this for a while. |
Closing, still tracked in #2390. |
Using
@SqlBatch
can be annoying because it uses a different interface from@SqlUpdate
and requires the user to do a lot of additional work (doesn't degrade gracefully). For example, let's say we start with a method to insert a row, which calls a DAO method that uses@SqlUpdate
:This method has non-trivial work that can't be done (easily) using
BeanMapper
or similar. I'm using some real code rather than a contrived example.We call the above method to insert single rows. Works great. Sometime later, we add another usage that calls this in a loop:
Later, we find out performance is bad if the number of items is large. How do we fix this?
We can convert the DAO to use
@SqlBatch
, but that requires the caller to either build seven separate collections for each variable parameter or to create a new bean object just for this. Both of these violate the encapsulation of theinsertColumn()
method by moving the work intoinsertColumns()
, which previously didn't have any details of the actual insert operation. It also breaks callers that were happily inserting a single row.One idea is to add a couple of methods to
SqlObject
:This doesn't handle returning generated keys. I was thinking users could add a separate method annotated with something like
@BatchFinisher
that would be used in place ofendBatch()
and would return generated keys. Though we could do the simple version first and tackle generated keys later.The text was updated successfully, but these errors were encountered: