? bin ? build.local.properties ? ping_patch Index: org/postgresql/core/ProtocolConnection.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/ProtocolConnection.java,v retrieving revision 1.6 diff -u -r1.6 ProtocolConnection.java --- org/postgresql/core/ProtocolConnection.java 21 Jun 2005 18:07:08 -0000 1.6 +++ org/postgresql/core/ProtocolConnection.java 5 Apr 2006 21:22:34 -0000 @@ -120,4 +120,10 @@ * @return the version of the implementation */ public int getProtocolVersion(); + + /** + * All user to ping the connection the database, + * + */ + public int ping(); } Index: org/postgresql/core/v2/ProtocolConnectionImpl.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/v2/ProtocolConnectionImpl.java,v retrieving revision 1.9 diff -u -r1.9 ProtocolConnectionImpl.java --- org/postgresql/core/v2/ProtocolConnectionImpl.java 2 Dec 2005 03:05:07 -0000 1.9 +++ org/postgresql/core/v2/ProtocolConnectionImpl.java 5 Apr 2006 21:22:34 -0000 @@ -193,6 +193,12 @@ return 2; } + public int ping() + { + // Not supported in V2. + return 0; + } + private String serverVersion; private int cancelPid; private int cancelKey; Index: org/postgresql/core/v3/ProtocolConnectionImpl.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/v3/ProtocolConnectionImpl.java,v retrieving revision 1.10 diff -u -r1.10 ProtocolConnectionImpl.java --- org/postgresql/core/v3/ProtocolConnectionImpl.java 2 Dec 2005 03:05:09 -0000 1.10 +++ org/postgresql/core/v3/ProtocolConnectionImpl.java 5 Apr 2006 21:22:35 -0000 @@ -188,6 +188,11 @@ { return 3; } + + public int ping() + { + return executor.ping(); + } private String serverVersion; private int cancelPid; Index: org/postgresql/core/v3/QueryExecutorImpl.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v retrieving revision 1.27 diff -u -r1.27 QueryExecutorImpl.java --- org/postgresql/core/v3/QueryExecutorImpl.java 30 Jan 2006 20:12:06 -0000 1.27 +++ org/postgresql/core/v3/QueryExecutorImpl.java 5 Apr 2006 21:22:37 -0000 @@ -21,6 +21,7 @@ import java.io.IOException; import java.sql.*; + import org.postgresql.Driver; import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLWarning; @@ -357,6 +358,33 @@ handler.handleCompletion(); } + + + public int ping() + { + int result = 0; + try + { + sendSync(); + int c = pgStream.ReceiveChar(); + if (c == 'Z') + { + receiveRFQ(); + result = 0; + } + else + { + result = -1; + } + } + catch (IOException ioe) + { + result = -2; + } + + return result; + } + private ResultHandler sendQueryPreamble(final ResultHandler delegateHandler, int flags) throws IOException { // First, send CloseStatements for finalized SimpleQueries that had statement names assigned. Index: org/postgresql/jdbc2/AbstractJdbc2Connection.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v retrieving revision 1.37 diff -u -r1.37 AbstractJdbc2Connection.java --- org/postgresql/jdbc2/AbstractJdbc2Connection.java 24 Nov 2005 06:44:21 -0000 1.37 +++ org/postgresql/jdbc2/AbstractJdbc2Connection.java 5 Apr 2006 21:22:40 -0000 @@ -1077,4 +1077,16 @@ { return bindStringAsVarchar; } + + /** + * Pings the postgresql database, will return <0 if the + * database is unavailable. + * + * @return + * @throws SQLException + */ + public int ping() + { + return protoConnection.ping(); + } } Index: org/postgresql/test/jdbc2/MiscTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/MiscTest.java,v retrieving revision 1.20 diff -u -r1.20 MiscTest.java --- org/postgresql/test/jdbc2/MiscTest.java 2 Dec 2005 03:05:10 -0000 1.20 +++ org/postgresql/test/jdbc2/MiscTest.java 5 Apr 2006 21:22:40 -0000 @@ -9,6 +9,7 @@ */ package org.postgresql.test.jdbc2; +import org.postgresql.jdbc2.AbstractJdbc2Connection; import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; @@ -67,6 +68,7 @@ stmt.cancel(); } } + public void testError() throws Exception { @@ -115,6 +117,15 @@ stmt.close(); con.close(); } + + public void testPint() throws Exception + { + Connection con = TestUtil.openDB(); + AbstractJdbc2Connection cn = (AbstractJdbc2Connection) con; + assertEquals(0, cn.ping()); + cn.close(); + } + public void xtestLocking() throws Exception {