pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dario V. Fassi <software@sistemat.com.ar>
To: Oliver Jowett <oliver@opencloud.com>
Cc: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: revisiting transaction isolation
Date: Sat, 17 Jul 2004 20:31:23 -0300
Message-ID: <40F9B6CB.6050407@sistemat.com.ar> (raw)
In-Reply-To: <40F9AF24.9090601@opencloud.com>
References: <40F8A692.8000105@opencloud.com>
	<Pine.BSO.4.56.0407170233550.32024@leary.csoft.net>
	<40F9AF24.9090601@opencloud.com>


The code bellow throw an exception and I can see any transaction in 
progress.

Dario.

        String url   = getJdbcUrl();
        try {
            isCon = false;
            con = DriverManager.getConnection( url, usr, pwd );
            if ( con == null ) return false;
            isCon = true;
            con.setAutoCommit( autoCommit );
            int tiso  = con.getTransactionIsolation();
            try {
                    dmd = con.getMetaData();
                    int defTxIsolation  = -1;
                    if ( dmd != null && 
dmd.supportsTransactionIsolationLevel( tranIsolation ) ) {
                        defTxIsolation = 
dmd.getDefaultTransactionIsolation();
                    }
                    if ( tranIsolation >= 0 && tranIsolation != 
defTxIsolation ) {
                        tranIsolation = defTxIsolation;
                    }
                }
                if ( tranIsolation >= 0 ) {
                    con.setTransactionIsolation( tranIsolation );
                    tiso = con.getTransactionIsolation();
                }
            } catch ( SQLException se ) {
                se.printStackTrace();
                lastErrMsg = "\n ERROR: TransactionIsolation No 
Soportado = " + Tools.InfoException( se );
            }


Oliver Jowett wrote:

> Kris Jurka wrote:
>
>>
>> On Sat, 17 Jul 2004, Oliver Jowett wrote:
>>
>>
>>> Currently, this type of code will fail:
>>>
>>>
>>>>  conn.setAutoCommit(false);
>>>>  if (conn.getTransactionIsolation() != 
>>>> Connection.TRANSACTION_SERIALIZABLE)
>>>>    conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
>>>
>>>
>>> The problem is that getTransactionIsolation() issues a query and 
>>> thus starts a new transaction, and then setTransactionIsolation() 
>>> complains you can't change isolation level mid-transaction.
>>>
>>> I'm not sure this is reasonable behaviour. One option is to make 
>>> getTransactionIsolation (and what other methods too?) not cause a 
>>> BEGIN to occur if there is no transaction in progress and autocommit 
>>> is off.
>>
>>
>>
>> I see no reason for getTransactionIsolation or any driver call to 
>> start a transaction, these are only SELECTs and won't be rolled back 
>> anyway.
>
>
> It's ok for getTransactionIsolation(), but what about, say, metadata 
> queries -- we do want transaction isolation to apply there even if 
> it's just a SELECT, right?
>
> A quick skim of AbstractJdbc2Connection turns up these methods as 
> candidates for ignoring autocommit:
>
>  - getTransactionIsolation()
>  - getPGType (both versions) on a cache miss
>
> It seems reasonable to suppress BEGINs for both of those cases. I can 
> put together a patch to do that. I'll leave the metadata queries alone 
> for the moment.
>
>>>> The return value of the method getTransactionIsolation should reflect
>>>> the change in isolation level when it actually occurs. [...]
>>>
>>
>> This seems confusing and error prone.
>
>
> Ok -- I'll leave that alone too.
>
> -O

view thread (6+ messages)  latest in thread

Message-ID: <40F9B6CB.6050407@sistemat.com.ar>
Permalink:  ../40F9B6CB.6050407@sistemat.com.ar/
Also on:    postgresql.org/message-id/40F9B6CB.6050407@sistemat.com.ar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: software@sistemat.com.ar, oliver@opencloud.com, books@ejurka.com
  Subject: Re: revisiting transaction isolation
  In-Reply-To: <40F9B6CB.6050407@sistemat.com.ar>
  References: <40F8A692.8000105@opencloud.com> <Pine.BSO.4.56.0407170233550.32024@leary.csoft.net> <40F9AF24.9090601@opencloud.com> <40F9B6CB.6050407@sistemat.com.ar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox