pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Benoit Foucher <benoit@ooc.com>
To: Postgres Interfaces <pgsql-interfaces@postgreSQL.org>
Subject: Isolation level support with JDBC
Date: Tue, 01 Jun 1999 12:08:47 -0400
Message-ID: <3754057B.1EE00F02@ooc.com> (raw)

Hi,

Since two different transaction isolation levels are supported
with Postgres 6.5 (READ_COMMITED and SERIALIZABLE), I've added 
support for setting and getting isolation level with
the two methods java.sql.Connection.setTransactionIsolation and 
java.sql.Connection.getTransactionIsolation. 

I'd like to know if my  modifications are correct (I've never 
developped such stuff before) and if it could be added to the 
jdbc driver sources.

I've attached the patch to this mail.

Thank you!
Regards

Benoit.

-- 
Benoit Foucher                                      mailto:benoit@ooc.com

Attachments:

jdbc.patch (application/octet-stream, 4.8K) download Index: Connection.java =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/interfaces/jdbc/postgresql/Connection.java,v retrieving revision 1.17 diff -u -r1.17 Connection.java --- Connection.java 1999/05/18 23:17:15 1.17 +++ Connection.java 1999/06/01 16:03:28 @@ -36,6 +36,7 @@ public boolean autoCommit = true; public boolean readOnly = false; + public int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED; public Driver this_driver; private String this_url; @@ -262,6 +263,13 @@ //if(msg.startsWith(dateStyles[i])) //currentDateStyle=i+1; // this is the index of the format //} + + if(msg.startsWith("NOTICE:") && msg.indexOf("TRANSACTION ISOLATION LEVEL")>0) { + msg = msg.substring(msg.indexOf("TRANSACTION ISOLATION LEVEL is ")+31); + if(msg.equals("SERIALIZABLE")) + isolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE; + else isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED; + } } /** Index: jdbc1/Connection.java =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/interfaces/jdbc/postgresql/jdbc1/Connection.java,v retrieving revision 1.2 diff -u -r1.2 Connection.java --- jdbc1/Connection.java 1999/05/18 23:17:21 1.2 +++ jdbc1/Connection.java 1999/06/01 16:03:29 @@ -311,7 +311,11 @@ */ public void setTransactionIsolation(int level) throws SQLException { - throw postgresql.Driver.notImplemented(); + if(level == java.sql.Connection.TRANSACTION_READ_COMMITTED) + ExecSQL("set transaction isolation level read commited"); + else if(level == java.sql.Connection.TRANSACTION_SERIALIZABLE) + ExecSQL("set transaction isolation level serializable"); + else throw postgresql.Driver.notImplemented(); } /** @@ -322,7 +326,9 @@ */ public int getTransactionIsolation() throws SQLException { - return java.sql.Connection.TRANSACTION_SERIALIZABLE; + ExecSQL("show transaction isolation level"); + + return isolationLevel; } /** Index: jdbc1/DatabaseMetaData.java =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java,v retrieving revision 1.1 diff -u -r1.1 DatabaseMetaData.java --- jdbc1/DatabaseMetaData.java 1999/01/17 04:51:54 1.1 +++ jdbc1/DatabaseMetaData.java 1999/06/01 16:03:41 @@ -1350,7 +1350,7 @@ */ public int getDefaultTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_SERIALIZABLE; + return Connection.TRANSACTION_READ_COMMITTED; } /** @@ -1379,8 +1379,9 @@ { if (level == Connection.TRANSACTION_SERIALIZABLE) return true; - else - return false; + else if(level == Connection.TRANSACTION_READ_COMMITTED) + return true; + else return false; } /** Index: jdbc2/Connection.java =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/interfaces/jdbc/postgresql/jdbc2/Connection.java,v retrieving revision 1.2 diff -u -r1.2 Connection.java --- jdbc2/Connection.java 1999/05/18 23:17:26 1.2 +++ jdbc2/Connection.java 1999/06/01 16:03:52 @@ -311,7 +311,11 @@ */ public void setTransactionIsolation(int level) throws SQLException { - throw postgresql.Driver.notImplemented(); + if(level == java.sql.Connection.TRANSACTION_READ_COMMITTED) + ExecSQL("set transaction isolation level read commited"); + else if(level == java.sql.Connection.TRANSACTION_SERIALIZABLE) + ExecSQL("set transaction isolation level serializable"); + else throw postgresql.Driver.notImplemented(); } /** @@ -322,7 +326,9 @@ */ public int getTransactionIsolation() throws SQLException { - return java.sql.Connection.TRANSACTION_SERIALIZABLE; + ExecSQL("show transaction isolation level"); + + return isolationLevel; } /** Index: jdbc2/DatabaseMetaData.java =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java,v retrieving revision 1.1 diff -u -r1.1 DatabaseMetaData.java --- jdbc2/DatabaseMetaData.java 1999/01/17 04:51:56 1.1 +++ jdbc2/DatabaseMetaData.java 1999/06/01 16:04:01 @@ -1350,7 +1350,7 @@ */ public int getDefaultTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_SERIALIZABLE; + return Connection.TRANSACTION_READ_COMMITTED; } /** @@ -1378,6 +1378,8 @@ public boolean supportsTransactionIsolationLevel(int level) throws SQLException { if (level == Connection.TRANSACTION_SERIALIZABLE) + return true; + else if (level == Connection.TRANSACTION_READ_COMMITTED) return true; else return false;

view thread (2+ messages)  latest in thread

Message-ID: <3754057B.1EE00F02@ooc.com>
Permalink:  ../3754057B.1EE00F02@ooc.com/
Also on:    postgresql.org/message-id/3754057B.1EE00F02@ooc.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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: benoit@ooc.com
  Subject: Re: Isolation level support with JDBC
  In-Reply-To: <3754057B.1EE00F02@ooc.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