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

Rows counter on Insert.Builder #33

Closed
arey opened this issue Feb 13, 2015 · 4 comments
Closed

Rows counter on Insert.Builder #33

arey opened this issue Feb 13, 2015 · 4 comments

Comments

@arey
Copy link
Contributor

arey commented Feb 13, 2015

We are using DbSetup to initialize a H2 database with large data set.
For each new use case of our integration tests, we have to add new rows.
Our requirement is to know how much rows we have inserted on some tables. We need this count number for assertion.
A getRowsCount() method on the Insert.Builder nested class would be welcome.
What do you think about this improvement?

@jnizet
Copy link
Member

jnizet commented Feb 13, 2015

Could you tell us more about why this method would be useful? Why isn't it possible to maintain a separate counter and increment it each time a row is inserted?
If this counter is really useful/necessary, shouldn't it be on Insert rather than Insert.Builder? Insert is immutable, and its number of rows never changes. Whereas Insert.Builder is mutable, its number of rows changes, and we can even be inside the creation of a row (which would make getRowCount() ambiguous).

@arey
Copy link
Contributor Author

arey commented Feb 16, 2015

We currently maintain a separate counter but the code is not pretty. See by yourself:

int rowCount = 
...
Insert.Builder builder = insertInto("MY_TABLE") .columns("ID", "DATE", "NAME");
Object[][] allValues = new Object[][]{ {1, "2015-02-16", "Name 1"},  /*...*/ }; 
rowCount = allValues.length; 
for (Object[] val : allValues) { 
    builder.values(val);
} 
return builder.build();

Thus a getRowCount() method on Insert would be useful.

@jnizet
Copy link
Member

jnizet commented Feb 16, 2015

OK. That doesn't hurt. I'll do that soon (probably Friday).

@jnizet
Copy link
Member

jnizet commented Feb 20, 2015

@arey I released version 1.4.0, containing the new method. It should appear on Maven central in the next hours.

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

No branches or pull requests

2 participants