0

I am using JOOQ ( 3.10. 5 ) to update records in ORACLE table without jooq auto code generation in below ways

Approach 1- Using DSL execute by using plain SQL String

dslContext.execute("update author set first_name = 'updateTest-111111' where id = 1 ");
logger.info("1st update Done ");

dslContext.execute("update author set first_name = 'updateTest-2222222' where id = 2 ");
logger.info("2nd update Done ");

Approach 2 - Using DSL batch by passing Query list

List<Query> updateQueries = new ArrayList<>();

updateQueries.add(dslContext.parser().parseQuery("update author set first_name = 'updateTest-111' where id = 1 "));

updateQueries.add(dslContext.parser().parseQuery("update author set first_name = 'updateTest-222' where id = 2 "));

dslContext.batch(updateQueries).execute();

But in both cases, it is just updating 1st record and then stop execution , keeps on running.

Below is the output for Approach -1

2022-05-13 02:43:50.848  INFO 25524 --- [nio-9010-exec-1] org.jooq.Constants                       : 
                                      
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@  @@        @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@        @@@@@@@@@@
@@@@@@@@@@@@@@@@  @@  @@    @@@@@@@@@@
@@@@@@@@@@  @@@@  @@  @@    @@@@@@@@@@
@@@@@@@@@@        @@        @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@        @@        @@@@@@@@@@
@@@@@@@@@@    @@  @@  @@@@  @@@@@@@@@@
@@@@@@@@@@    @@  @@  @@@@  @@@@@@@@@@
@@@@@@@@@@        @@  @  @  @@@@@@@@@@
@@@@@@@@@@        @@        @@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  Thank you for using jOOQ 3.10.5
                                      
2022-05-13 02:43:50.922  WARN 25524 --- [nio-9010-exec-1] o.a.tomcat.jdbc.pool.ConnectionPool      : minIdle is larger than maxActive, setting minIdle to: 5
2022-05-13 02:43:50.923  WARN 25524 --- [nio-9010-exec-1] o.a.tomcat.jdbc.pool.ConnectionPool      : maxIdle is larger than maxActive, setting maxIdle to: 5
2022-05-13 02:43:52.670  INFO 25524 --- [nio-9010-exec-1] c.d.e.dao.ECRebootServiceDaoImpl         : 1st update Done 

As you can see it stopped after 1st update Done.

How i should be executing multiple update queries using JOOQ ? or is there any better way to do this in JOOQ without code generation?

codiacTushki
  • 750
  • 1
  • 9
  • 22

1 Answers1

0

The problem you encountered

The most likely reason for the problem you've encountered is that you have locked the row in another transaction (e.g. in a SQL editor?) and now your program is blocked right after printing the debug message, in the update.

Regarding your queries

With both of your approaches, you're not using bind variables, which will be a problem for Oracle's cursor cache, producing cursor cache contention. At the least, you should execute something like this:

ctx.execute("update author set first_name = ? where id = ?", "updateTest-111111", 1);
ctx.execute("update author set first_name = ? where id = ?", "updateTest-2222222", 2);

In the batch case, you have used the jOOQ parser to get a Query representation of your string, but in your case, that seems to be overkill. You can wrap any plain SQL string in a Query using DSLContext.query(String).

In that case, again, it would be better to use bind variables, e.g. like this:

ctx.batch(query("update author set first_name = ? where id = ?"))
   .bind("updateTest-111", 1)
   .bind("updateTest-222", 2)
   .execute();

Or even just:

ctx.batch("update author set first_name = ? where id = ?")
   .bind("updateTest-111", 1)
   .bind("updateTest-222", 2)
   .execute();

Regarding code generation

I suggest you reconsider using code generation. While there isn't much benefit in your particular case (at least the parts you've shared in this question), it is very useful in general.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • I tried using code generation but got below issue , so believe it need enterprise license 13:14:52.028 [main] INFO org.jooq.util.GenerationTool - Initialising properties : C:\Users\TestUser\IdeaProjects\ccb-data-eucservice\library.xml 13:14:55.889 [main] WARN org.jooq.util.GenerationTool - Type not found : Your configured database type was not found. This can have several reasons: - You want to use a commercial jOOQ Edition, but you pulled the Open Source Edition from Maven Central. - You have mis-typed your class name. – codiacTushki May 13 '22 at 07:49
  • @codiacTushki: Yes, the jOOQ Open Source Edition doesn't support the Oracle dialect, only the commercial editions do. – Lukas Eder May 13 '22 at 08:09
  • I am using below dependency for codegen now org.jooq jooq-codegen-maven 3.10.5 Is there any different dependency for enterprise one. I want to check on our local artifact if enterprise one is present or not – codiacTushki May 13 '22 at 11:49
  • @codiacTushki: Does this help? https://www.jooq.org/doc/latest/manual/code-generation/codegen-maven/ – Lukas Eder May 13 '22 at 12:57
  • Thanks, it is having information which I was looking for – codiacTushki May 14 '22 at 08:35