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

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

This comment has been minimized.

Show comment
Hide comment
@jnizet

jnizet Feb 13, 2015

Member

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).

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

This comment has been minimized.

Show comment
Hide comment
@arey

arey Feb 16, 2015

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@jnizet

jnizet Feb 16, 2015

Member

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

Member

jnizet commented Feb 16, 2015

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

@jnizet jnizet closed this in 749a0f3 Feb 20, 2015

@jnizet jnizet added the enhancement label Feb 20, 2015

@jnizet

This comment has been minimized.

Show comment
Hide comment
@jnizet

jnizet Feb 20, 2015

Member

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

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