This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to annotated tag REL9_3_1100 in repository libpostgresql-jdbc-java.
commit 7366eebe7d9fd1686d26851674476010b44cbaf4 Author: Steven Schlansker <[email protected]> Date: Sun Dec 30 11:06:43 2012 -0800 Allow driver to set read-only based on a connection parameter. --- org/postgresql/Driver.java.in | 1 + org/postgresql/jdbc2/AbstractJdbc2Connection.java | 6 ++++++ org/postgresql/test/jdbc2/DriverTest.java | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/org/postgresql/Driver.java.in b/org/postgresql/Driver.java.in index f6c69c0..27d8115 100644 --- a/org/postgresql/Driver.java.in +++ b/org/postgresql/Driver.java.in @@ -182,6 +182,7 @@ public class Driver implements java.sql.Driver * user - (required) The user to connect as * password - (optional) The password for the user * ssl - (optional) Use SSL when connecting to the server + * readOnly - (optional) Set connection to read-only by default * charSet - (optional) The character set to be used for converting * to/from the database to unicode. If multibyte is enabled on the * server then the character set of the database is used as the default, diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java index 2fb37f4..2dbc6aa 100644 --- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java +++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java @@ -137,6 +137,12 @@ public abstract class AbstractJdbc2Connection implements BaseConnection this.dbVersionNumber = protoConnection.getServerVersion(); this.compatible = info.getProperty("compatible", Driver.MAJORVERSION + "." + Driver.MINORVERSION); + // Set read-only early if requested + if (Boolean.valueOf(info.getProperty("readOnly", "false"))) + { + setReadOnly(true); + } + // Formats that currently have binary protocol support Set<Integer> binaryOids = new HashSet<Integer>(); if (binaryTransfer && protoConnection.getProtocolVersion() >= 3) { diff --git a/org/postgresql/test/jdbc2/DriverTest.java b/org/postgresql/test/jdbc2/DriverTest.java index 9df5751..50726ac 100644 --- a/org/postgresql/test/jdbc2/DriverTest.java +++ b/org/postgresql/test/jdbc2/DriverTest.java @@ -98,4 +98,27 @@ public class DriverTest extends TestCase con.close(); } + + /* + * Test that the readOnly property works. + */ + public void testReadOnly() throws Exception + { + TestUtil.initDriver(); // Set up log levels, etc. + + Connection con = DriverManager.getConnection(TestUtil.getURL() + "&readOnly=true", TestUtil.getUser(), TestUtil.getPassword()); + assertNotNull(con); + assertTrue(con.isReadOnly()); + con.close(); + + con = DriverManager.getConnection(TestUtil.getURL() + "&readOnly=false", TestUtil.getUser(), TestUtil.getPassword()); + assertNotNull(con); + assertFalse(con.isReadOnly()); + con.close(); + + con = DriverManager.getConnection(TestUtil.getURL(), TestUtil.getUser(), TestUtil.getPassword()); + assertNotNull(con); + assertFalse(con.isReadOnly()); + con.close(); + } } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

