Skip site navigation (1) Skip section navigation (2)

It is safe remenber current Isolation level in AbstractJdbc2Connection?

From: Ader Javier <javierader(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: It is safe remenber current Isolation level in AbstractJdbc2Connection?
Date: 2010-04-11 03:41:07
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
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() !=

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
//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
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

Ader Javier


pgsql-jdbc by date

Next:From: Maciek SakrejdaDate: 2010-04-11 04:06:10
Subject: Re: It is safe remenber current Isolation level in AbstractJdbc2Connection?
Previous:From: Radosław SmoguraDate: 2010-04-10 12:58:54
Subject: Re: Migration to Hibernate 3.5 final

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group