Hi Luke,

Thanks for your reply. I tried to opt for OL as you have mentioned , in the
following code:

public void runQueries2() {
        String userName = "bidev";
        String password = "biapp";
        String url = "jdbc:postgresql://localhost:5432/postgres";

        try {
            Connection conn = DriverManager.getConnection(url, userName,
password)
            Configuration configuration = new DefaultConfiguration()
                    .set(conn)
                    .set(SQLDialect.POSTGRES);

            configuration.settings().withExecuteWithOptimisticLocking(true);

            conn.setAutoCommit(false);
            Connection conn1 = DriverManager.getConnection(url, userName,
password);
            conn1.setAutoCommit(false);
            Configuration configuration1 = new DefaultConfiguration()
                    .set(conn1)
                    .set(SQLDialect.POSTGRES);


configuration1.settings().withExecuteWithOptimisticLocking(true);
            DSLContext context = DSL.using(configuration);

            DSLContext context1 = DSL.using(configuration1);
            context1.update(Layout.LAYOUT)
                    .set(Layout.LAYOUT.HEIGHT,200)
                    .where(Layout.LAYOUT.ID.eq(1L))
                    .returning(Layout.LAYOUT.ID)
                    .fetchOne();
            context.update(Layout.LAYOUT)
                    .set(Layout.LAYOUT.HEIGHT,10)
                    .where(Layout.LAYOUT.ID.eq(1L))
                    .returning(Layout.LAYOUT.ID)
                    .fetchOne();

            conn.commit();
            conn1.commit();
        }

        //TODO: should be throwing it back..
        catch (Exception e) {
            e.printStackTrace();
        }
}

But the code does end up in a deadlock. Note that here I'm just mimicking
the scenario. Layout schema looks like the following:

CREATE TABLE LAYOUT(
  ID BIGSERIAL PRIMARY KEY NOT NULL,
  DID SERIAL REFERENCES DATASOURCE (ID),
  VERSION_ID INTEGER,
  TYPE VARCHAR(30) NOT NULL,
  QUERY VARCHAR(500) NOT NULL,
  WIDTH INTEGER,
  HEIGHT INTEGER,
  POSIITION INTEGER,
  LAYOUT JSONB NULL
);

and the in the code generation I have used the following:

<recordVersionFields>VERSION_ID</recordVersionFields>

Not sure, where I'm making the mistake.

On Mon, Sep 4, 2017 at 3:19 PM, Lukas Eder <[email protected]> wrote:

> Hi Kamal,
>
> Thanks for your message. I'll comment inline
>
> 2017-09-03 16:38 GMT+02:00 Kamal raj <[email protected]>:
>
>> 1. Need to enable the OL in Jooq using  executeWithOptimisticLocking
>> settings
>>
>
> Yes
>
>
>> 2. Since OL in Jooq automatically throws / fails when see the concurrent
>> modification, I believe its totally fine to run them in any transaction
>> mode (note that I'm using Postgres here). My understanding here is that OL
>> themselves hides the complexity of transaction. May be I'm wrong here.
>> Please correct me.
>>
>
> Well, to get a completely accurate picture, the usual transaction
> anomalies can still happen under non-serializable transaction isolation -
> although, I cannot think of such an edge case right now.
>
>
>> 3. How does Jooq knows which column it needs to watch while versioning
>> under OL? The documentation from here : https://www.jooq.org/doc/2.5
>> /manual/sql-execution/crud-with-updatablerecords/optimistic-locking/
>> says that, we can create a column called MODIFIED as a TIMESTAMP. But the
>> question here is, how does the column mapping works w.r.t to OL?
>>
>
> Follow the link to the manual sections about the code generator
> configuration. You can specify the columns to be used as version /
> timestamp columns here:
> https://www.jooq.org/doc/latest/manual/code-generation/
> codegen-advanced/codegen-config-record-version-timestamp-fields
>
> I hope this helps,
> Lukas
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jOOQ User Group" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/jooq-user/VLWO1rFJ4AM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to