Rows counter on Insert.Builder #33

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

Projects

None yet

2 participants

@arey
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
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
Contributor
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
Member
jnizet commented Feb 16, 2015

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

@jnizet jnizet added a commit that closed this issue Feb 20, 2015
@jnizet jnizet add a getRowCount() method on Insert
fix #33
749a0f3
@jnizet jnizet closed this in 749a0f3 Feb 20, 2015
@jnizet jnizet added the enhancement label Feb 20, 2015
@jnizet
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