This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL9_3_1103 in repository libpostgresql-jdbc-java.
commit bf8da8acad9f0a598429ee32964f66db8e461712 Author: Dave Cramer <[email protected]> Date: Fri Sep 12 15:48:17 2014 +0000 backpatched Statement.isClosed() implementation of PGPoolingDataSource with some performance improvements. #180 --- .../ds/jdbc23/AbstractJdbc23PooledConnection.java | 142 ++++++++++----------- org/postgresql/util/GT.java | 10 +- src/pom/pom.xml | 3 +- 3 files changed, 77 insertions(+), 78 deletions(-) diff --git a/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java b/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java index 4ce1b3a..9fa83ff 100644 --- a/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java +++ b/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java @@ -27,7 +27,7 @@ import org.postgresql.util.PSQLState; */ public abstract class AbstractJdbc23PooledConnection { - private List listeners = new LinkedList(); + private final List<ConnectionEventListener> listeners = new LinkedList<ConnectionEventListener>(); private Connection con; private ConnectionHandler last; private final boolean autoCommit; @@ -78,7 +78,7 @@ public abstract class AbstractJdbc23PooledConnection { con.rollback(); } - catch (SQLException e) + catch (SQLException ignored) { } } @@ -129,7 +129,7 @@ public abstract class AbstractJdbc23PooledConnection { con.rollback(); } - catch (SQLException e) + catch (SQLException ignored) { } } @@ -163,10 +163,9 @@ public abstract class AbstractJdbc23PooledConnection { ConnectionEvent evt = null; // Copy the listener list so the listener can remove itself during this method call - ConnectionEventListener[] local = (ConnectionEventListener[]) listeners.toArray(new ConnectionEventListener[listeners.size()]); - for (int i = 0; i < local.length; i++) + ConnectionEventListener[] local = listeners.toArray(new ConnectionEventListener[listeners.size()]); + for (ConnectionEventListener listener : local ) { - ConnectionEventListener listener = local[i]; if (evt == null) { evt = createConnectionEvent(null); @@ -182,10 +181,9 @@ public abstract class AbstractJdbc23PooledConnection { ConnectionEvent evt = null; // Copy the listener list so the listener can remove itself during this method call - ConnectionEventListener[] local = (ConnectionEventListener[])listeners.toArray(new ConnectionEventListener[listeners.size()]); - for (int i = 0; i < local.length; i++) + ConnectionEventListener[] local = listeners.toArray(new ConnectionEventListener[listeners.size()]); + for (ConnectionEventListener listener : local ) { - ConnectionEventListener listener = local[i]; if (evt == null) { evt = createConnectionEvent(e); @@ -219,8 +217,8 @@ public abstract class AbstractJdbc23PooledConnection if (state.length() < 2) // no class info, assume fatal return true; - for (int i = 0; i < fatalClasses.length; ++i) - if (state.startsWith(fatalClasses[i])) + for ( String fatalClass : fatalClasses ) + if (state.startsWith(fatalClass)) return true; // fatal return false; @@ -261,41 +259,37 @@ public abstract class AbstractJdbc23PooledConnection public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + final String methodName=method.getName(); // From Object if (method.getDeclaringClass().getName().equals("java.lang.Object")) { - if (method.getName().equals("toString")) + if (methodName.equals("toString")) { return "Pooled connection wrapping physical connection " + con; } - if (method.getName().equals("equals")) + if (methodName.equals("equals")) { - return new Boolean(proxy == args[0]); + return proxy == args[0]; } - if (method.getName().equals("hashCode")) + if (methodName.equals("hashCode")) { - return new Integer(System.identityHashCode(proxy)); + return System.identityHashCode(proxy); } try { return method.invoke(con, args); } - catch (InvocationTargetException e) + catch (InvocationTargetException ite) { - throw e.getTargetException(); + throw ite.getTargetException(); } } // All the rest is from the Connection or PGConnection interface - if (method.getName().equals("isClosed")) + if (methodName.equals("isClosed")) { - return con == null ? Boolean.TRUE : Boolean.FALSE; + return con == null || con.isClosed(); } - if (con == null && !method.getName().equals("close")) - { - throw new PSQLException(automatic ? GT.tr("Connection has been closed automatically because a new connection was opened for the same PooledConnection or the PooledConnection has been closed.") : GT.tr("Connection has been closed."), - PSQLState.CONNECTION_DOES_NOT_EXIST); - } - if (method.getName().equals("close")) + if (methodName.equals("close")) { // we are already closed and a double close // is not an error. @@ -303,18 +297,21 @@ public abstract class AbstractJdbc23PooledConnection return null; SQLException ex = null; - if (!isXA && !con.getAutoCommit()) + if (!con.isClosed()) { - try - { + if (!isXA && !con.getAutoCommit()) + { + try + { con.rollback(); - } - catch (SQLException e) - { - ex = e; - } + } + catch (SQLException ignored) + { + ex = ignored; + } + } + con.clearWarnings(); } - con.clearWarnings(); con = null; this.proxy = null; last = null; @@ -325,22 +322,26 @@ public abstract class AbstractJdbc23PooledConnection } return null; } - + if (con == null || con.isClosed()) + { + throw new PSQLException(automatic ? GT.tr("Connection has been closed automatically because a new connection was opened for the same PooledConnection or the PooledConnection has been closed.") : GT.tr("Connection has been closed."), + PSQLState.CONNECTION_DOES_NOT_EXIST); + } + // From here on in, we invoke via reflection, catch exceptions, // and check if they're fatal before rethrowing. - - try { - if (method.getName().equals("createStatement")) + try { + if (methodName.equals("createStatement")) { Statement st = (Statement)method.invoke(con, args); return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Statement.class, org.postgresql.PGStatement.class}, new StatementHandler(this, st)); } - else if (method.getName().equals("prepareCall")) + else if (methodName.equals("prepareCall")) { Statement st = (Statement)method.invoke(con, args); return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{CallableStatement.class, org.postgresql.PGStatement.class}, new StatementHandler(this, st)); } - else if (method.getName().equals("prepareStatement")) + else if (methodName.equals("prepareStatement")) { Statement st = (Statement)method.invoke(con, args); return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{PreparedStatement.class, org.postgresql.PGStatement.class}, new StatementHandler(this, st)); @@ -349,10 +350,10 @@ public abstract class AbstractJdbc23PooledConnection { return method.invoke(con, args); } - } catch (InvocationTargetException e) { - Throwable te = e.getTargetException(); + } catch (final InvocationTargetException ite) { + final Throwable te = ite.getTargetException(); if (te instanceof SQLException) - fireConnectionError((SQLException)te); // Tell listeners about exception if it's fatal + fireConnectionError((SQLException) te); // Tell listeners about exception if it's fatal throw te; } } @@ -392,69 +393,68 @@ public abstract class AbstractJdbc23PooledConnection * Connection proxy for the getConnection method. */ private class StatementHandler implements InvocationHandler { - private AbstractJdbc23PooledConnection.ConnectionHandler con; + private ConnectionHandler con; private Statement st; - public StatementHandler(AbstractJdbc23PooledConnection.ConnectionHandler con, Statement st) { + public StatementHandler(ConnectionHandler con, Statement st) { this.con = con; this.st = st; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + final String methodName = method.getName(); // From Object if (method.getDeclaringClass().getName().equals("java.lang.Object")) { - if (method.getName().equals("toString")) + if (methodName.equals("toString")) { return "Pooled statement wrapping physical statement " + st; } - if (method.getName().equals("hashCode")) + if (methodName.equals("hashCode")) { - return new Integer(System.identityHashCode(proxy)); + return System.identityHashCode(proxy); } - if (method.getName().equals("equals")) + if (methodName.equals("equals")) { - return new Boolean(proxy == args[0]); + return proxy == args[0]; } return method.invoke(st, args); } + // All the rest is from the Statement interface - if (method.getName().equals("close")) + if (methodName.equals("isClosed")) { - // closing an already closed object is a no-op - if (st == null || con.isClosed()) + return st == null || st.isClosed(); + } + if (methodName.equals("close")) + { + if (st == null || st.isClosed()) return null; - - try - { - st.close(); - } - finally - { - con = null; - st = null; - } + con = null; + final Statement oldSt = st; + st = null; + oldSt.close(); return null; } - if (st == null || con.isClosed()) + if (st == null || st.isClosed()) { throw new PSQLException(GT.tr("Statement has been closed."), - PSQLState.OBJECT_NOT_IN_STATE); + PSQLState.OBJECT_NOT_IN_STATE); } - - if (method.getName().equals("getConnection")) + if (methodName.equals("getConnection")) { return con.getProxy(); // the proxied connection, not a physical connection } + // Delegate the call to the proxied Statement. try { return method.invoke(st, args); - } catch (InvocationTargetException e) { - Throwable te = e.getTargetException(); + } catch (final InvocationTargetException ite) { + final Throwable te = ite.getTargetException(); if (te instanceof SQLException) - fireConnectionError((SQLException)te); // Tell listeners about exception if it's fatal + fireConnectionError((SQLException) te); // Tell listeners about exception if it's fatal throw te; } } diff --git a/org/postgresql/util/GT.java b/org/postgresql/util/GT.java index fbda0ae..90bbc28 100644 --- a/org/postgresql/util/GT.java +++ b/org/postgresql/util/GT.java @@ -8,8 +8,8 @@ package org.postgresql.util; import java.text.MessageFormat; -import java.util.ResourceBundle; import java.util.MissingResourceException; +import java.util.ResourceBundle; /** * This class provides a wrapper around a gettext message catalog that @@ -24,15 +24,15 @@ public class GT { private final static GT _gt = new GT(); private final static Object noargs[] = new Object[0]; - public final static String tr(String message) { + public static String tr(String message) { return _gt.translate(message, null); } - public final static String tr(String message, Object arg) { + public static String tr(String message, Object arg) { return _gt.translate(message, new Object[]{arg}); } - public final static String tr(String message, Object args[]) { + public static String tr(String message, Object args[]) { return _gt.translate(message, args); } @@ -51,7 +51,7 @@ public class GT { } } - private final String translate(String message, Object args[]) + private String translate(String message, Object args[]) { if (_bundle != null && message != null) { diff --git a/src/pom/pom.xml b/src/pom/pom.xml index 4dabcd2..91d4783 100644 --- a/src/pom/pom.xml +++ b/src/pom/pom.xml @@ -31,8 +31,7 @@ </licenses> <scm> <connection>scm:git:[email protected]:pgjdbc/pgjdbc.git</connection> - <developerConnection>scm:git:[email protected]:pgjdbc/pgjdbc.git</developerConnection> - <url>[email protected]:pgjdbc/pgjdbc.git</url> + <url>https://github.com/pgjdbc/pgjdbc</url> </scm> <distributionManagement> <repository> -- 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

