stevensouza / jamonapi

Another repo for jamonapi.com which is primarily hosted on sourceforge
57 stars 24 forks source link

executeBatch #15

Open Rominet13 opened 8 years ago

Rominet13 commented 8 years ago

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 commented 8 years ago

Could you show me the actual batch code?

Rominet13 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

Rominet13 commented 8 years ago

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:

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 commented 8 years ago

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 commented 8 years ago

Done