Tuesday, 15 January 2013

java - Using the MockDataProvider of JOOQ, how do I set the lastId() that gets returned? -


Note: I am not using jooq's code generator

  DSLContext ctx = DSL.using (no actual database has been contacted because I am using the MOCKONNICATION and MOCKETPROVIDER JOOQ.  

connection, SQLDialect.MYSQL); // Insert // Find Bigger ID = Ctx list ();

JOOQ performs the following query:

  last_insert_id () Select Dual;  

In my MockDataProvider I check when this query is executed and returns the result accordingly:

  import static org.jooq.impl.DSL Dual; // Execute another code @ Override public Mok Result [] (MockXtequettentex CTX) throws SQL Consection {field & lt; Bigenter & gt; Id = DSL.field ("", BigInteger.Class); Record record = dual () NewRecord (); Record.setValue (id, BigInterview.auview (1234567)); Return the new Mock Result [] (New MockScult (record)}}  

The above MockResult is back, so I get the following exception

  java .lang.IllegalArgumentException: field () is not included in the line  

What is the correct way to populate the MockResult for the query (last_insert_id)?

This is an implementation implementation for MockDataProvider for DSLContext.lastID () :

  Expect BigInteger = BigInteger valueOf (1234567); DSLContext ct X = DSL.using (new mock connection (c -> gt; field & lt; bigenter & gt; id = DSL.field ("last_insert_id ()", BigInteger.class); record record = DSL.using (MYSQL) Newrecord (ID); Record. Set Value (ID, Expected); New Mock Result [] (New Mockeryzalt (Record)}}), SQLEact.MYSQL; AssertEquals (Expected, ctx.lastID ());  

There are essentially two things that have gone wrong in your view:

Field Name

Field name of the field that you are choosing In essence, it is called last_insert_id () (at least jOOQ 3.5.3), so you have to give your duplicate field a name like this:

  Field & lt; BigInteger & gt; Id = DSL.field ("last_insert_id ()", BigInteger.Class);  

record

You will have to create that record in which it already has your field. There is a separate area in the table. The fact that jooq generates a dual query is irrelevant to the fact that you record in which the last_insert_id () field is:

record record = DSL.USING (MISSQL). Newrecard (ID);

Warning

Of course, you are making a strong assumption about the implementation of Joaqu's because it is in 3.5.3. There is no guarantee that exact query generated by DSLContext.lastID () should always be

  last_insert_id () select double  

No comments:

Post a Comment