Skip to content
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

Collection of DTOs as input parameters #11

Open
dmitrydrugi opened this issue Feb 18, 2022 · 2 comments
Open

Collection of DTOs as input parameters #11

dmitrydrugi opened this issue Feb 18, 2022 · 2 comments

Comments

@dmitrydrugi
Copy link

Hi Team,

The library supports var args to pass multiple objects:

var account1 = new Account(1, "John");
var account2 = new Account(2, "Mary");
client.forSql("INSERT INTO accounts(accountId, name) VALUES(:accountId, :name)")
         .withParamSets(account1, account2)
         .execute();   

If we need to pass Collection we have to call toArray():

List<Account> accounts = List.of(new Account(1, "John"), new Account(2, "Mary")....);
client.forSql("INSERT INTO accounts(accountId, name) VALUES(:accountId, :name)")
         .withParamSets(accounts.toArray())
         .execute();   

Batch saving quite often is used with a list of objects and it would help to avoid extra call toArray().

Could you please add overloaded withParamSets method or a new method to pass java.util.Collection, for instance:

List<Account> accounts = List.of(new Account(1, "John"), new Account(2, "Mary")....);
client.forSql("INSERT INTO accounts(accountId, name) VALUES(:accountId, :name)")
         .withParamCollection(accounts)
         .execute();   

Thank you.

@sp0l
Copy link

sp0l commented Feb 18, 2022

Hi, there is already an overloaded method:

public Executor withParamSets(List<Object> params)

@dmitrydrugi
Copy link
Author

dmitrydrugi commented Feb 18, 2022

Hi,

Okay, thank you.

I have found a bug. If we pass a list with one item only it doesn't work:

List<Account> accounts = List.of(new Account(1, "John"));
client.forSql("INSERT INTO accounts(accountId, name) VALUES(:accountId, :name)")
         .withParamSets(accounts)
         .execute();   

However if we use the second method it works as expected:

List<Account> accounts = List.of(new Account(1, "John"));
client.forSql("INSERT INTO accounts(accountId, name) VALUES(:accountId, :name)")
         .withParamSets(accounts.toArray())
         .execute();   

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants