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

executeBatch #15

Open
Rominet13 opened this issue Jun 28, 2016 · 7 comments
Open

executeBatch #15

Rominet13 opened this issue Jun 28, 2016 · 7 comments

Comments

@Rominet13
Copy link

Hello @stevensouza
First, thank you for JAMon

As you may know the JDBC proxy misses queries sent by the executeBatch method.
I have been able to catch them by enabling the monitor on this method, in the "JDBCMonProxy" class, in the "isExecuteQueryMethod" :
<< private boolean isExecuteQueryMethod(String methodName) {
return "executeQuery".equals(methodName) || "executeUpdate".equals(methodName) || "execute".equals(methodName) || "executeBatch".equals(methodName);
} >>

(my application uses PreperedStatement in this case)
It catches the 3 queries but the figures aren't good:
JAMonExecuteBatch.xlsx
I get:
Hits Avg total
9470 0,293664203 2781
9470 0,293980993 2784
9470 0,755649419 7156
while i should have:
Hits
9470 (Parent Table)
94700 (Child Table)
37880 (Child Table)

It seems they share the same figures while they shoudn't.
Is it possible to "simply" resolve it in JAMon or is it a deep JDBC problem (i'm afraid it is) ?

@stevensouza
Copy link
Owner

Could you show me the actual batch code?

@Rominet13
Copy link
Author

Sorry i can't show you the exact code. I can just explain it.

We use this class:
org.springframework.jdbc.core.JdbcTemplate
method:
batchUpdate(String sql, final BatchPreparedStatementSetter pss)
We use a "new BatchPreparedStatementSetter()" as "pss" parameter where we overide the 2 methods:
setValues
getBatchSize

We use it for the parent table, again we use this batchUpdate method for the 2 child tables.

So we use 3 batchUpdate methods in a row in our writer class.

@stevensouza
Copy link
Owner

Even if you can't use your exact tables, can you give the example in code with fictitious table names, or preferably a working example I can run.

@Rominet13
Copy link
Author

i'm a bit busy now, but i will see what can do.

@Rominet13
Copy link
Author

Hi,
in fact, the result is absolutely correct depending on how you see SQL queries: from the database or from the network(or the application).
And from the network, since it's an "executeBatch()" method, there is 1 one query, which in fact contains dozens of SQL queries.
Then you have to choose which of the hits you want...

Network view
The hits is coherent since it refers to the method invocation.
In this case you just need to add the method "executeBatch" (like I have done in my first message) but it doesn't work if it is made with "Statement".
(indeed, "executeBatch()" don't have argument contrary to other JDBC method with "Statement" (ex: statement.execute( String Query)),
while the way to differentiate a PreparedStatement and a Statement in JAMon is the presence of argument. ) It 's probably the reason you ignored this case.
So if you are using "Statement", I throw an "UnsupportedOperationException("Doesn't support executeBatch with Statement")".
Nevertheless, there are solutions to monitor this case:
- change the way JAMon detect PS o Statement. //By the way, why do you use arguments to distinguish PS and Statement?(performance?)
- get the query in the method addBatch(String query)...

Database view
In my case, I rather use the real number of SQL queries, so I get the size of the "int[]" return by "executeBatch" which correspond to the number of SQL queries.
I keep the UnsupportedOperationException in case of statement.

Thanks, I have use your unit test ("MonProxyTest.java") and your embedded database, it was very usefull!!

@stevensouza
Copy link
Owner

Did you make changes to the code? If so, if you issue a pull request I will look at it for inclusion into jamon.

Thanks,
Steve

@Rominet13
Copy link
Author

Done

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