pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Maciek Sakrejda <msakrejda@truviso.com>
To: Ader Javier <javierader@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: It is safe remenber current Isolation level in AbstractJdbc2Connection?
Date: Sat, 10 Apr 2010 21:06:10 -0700
Message-ID: <h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com> (raw)
In-Reply-To: <4BC144D3.4030808@gmail.com>
References: <4BC144D3.4030808@gmail.com>

The one problem I see is that an explicit "SET TRANSACTION
SERIALIZABLE" through a plain query will foil your scheme, but given
that ReadOnly is already handled that way, this may be a moot point...
---
Maciek Sakrejda | Software Engineer | Truviso

1065 E. Hillsdale Blvd., Suite 230
Foster City, CA 94404
(650) 242-3500 Main
(650) 242-3501 F
www.truviso.com



On Sat, Apr 10, 2010 at 8:41 PM, Ader Javier <javierader@gmail.com> wrote:
> Hi and sorry by my English. I have a software that checks the Isolation
>  level before create "every" PreparedStatement over a Connection (there
> is a pool of connections from we pick one). Some like this:
>  if( connection.getTransactionIsolation() !=
> Connection.TRANSACTION_READ_COMMITTED ) {
>                    connection.setTransactionIsolation(
> Connection.TRANSACTION_READ_COMMITTED );
>                }
>
> ....
> PreparedStatement stmt = connection.createPreparedStatement(....)
> return stmt;
>
> My problem is that AbstractJdbc2Connection.getTransactionIsolation()
> access the server ever and don't remember the last level used, so It's
> safe change getTransactionIsolation() and setTransactionIsolation(level)
> for avoid unnecessary access? That's my idea
> public abstract class AbstractJdbc2Connection implements BaseConnection
> {
> ....
> //cached Isolation level
> private Integer level = null;
> ....
> public int getTransactionIsolation() throws SQLException
> {
> checkClosed();
> //new : avoid access if there is one previous
> if (this.level != null) return this.level.intValue();
>
> ....
> ....
>
> level = level.toUpperCase(Locale.US);
> // mod: caching before return return
> if (level.indexOf("READ COMMITTED") != -1)
>  this.level = new Integer(Connection.TRANSACTION_READ_COMMITTED);
> if (level.indexOf("READ UNCOMMITTED") != -1)
>  this.level= new Integer(Connection.TRANSACTION_READ_UNCOMMITTED);
> if (level.indexOf("REPEATABLE READ") != -1)
>  this.level = new Integer(Connection.TRANSACTION_REPEATABLE_READ)
> if (level.indexOf("SERIALIZABLE") != -1)
>  this.level = new Integer(Connection.TRANSACTION_SERIALIZABLE);
>
> if (this.level != null)
>  return this.level.valueInt();
>
> this.level = new Integer(Connection.TRANSACTION_READ_COMMITTED); // Best
> guess
> return this.level.valueInt();
> }
>
> public void setTransactionIsolation(int level) throws SQLException
> {
> ...
>
> //new: caching before return
> this.level = new Integer(level);
> }
>
> By the way, property "read only" is managed in this way (see
> AbstractJdbc2Connection.getReadOnly() and
> AbstractJdbc2Connection.setReadOnly(boolean).
>
> Thanks!
> Ader Javier
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>



view thread (3+ messages)  latest in thread

Message-ID: <h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com>
Permalink:  ../h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com/
Also on:    postgresql.org/message-id/h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com

 · 

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: msakrejda@truviso.com, javierader@gmail.com
  Subject: Re: It is safe remenber current Isolation level in AbstractJdbc2Connection?
  In-Reply-To: <h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com>
  References: <4BC144D3.4030808@gmail.com> <h2w895e58dd1004102106g11ace8e6m421697d150c75ebc@mail.gmail.com>

* 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