--Apple-Mail-7--324416721
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
Several jdbc drivers have recently added a way to set the SOTimeout
on the connections socket. For those of us accessing databases over a
unreliable connections, this can be quite helpful.
Attached is a patch to add sup****t for an additional url property
"socketTimeout" and property in the DataSource cl*****. The property
is in seconds (like jtds and IBM DB2's driver and unlike the Oracle
driver).
--Apple-Mail-7--324416721
Content-Disposition: attachment;
filename=postgresql-jdbc-8.3-603-add_socket_timeout_property.diff
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="postgresql-jdbc-8.3-603-add_socket_timeout_property.diff"
Content-Transfer-Encoding: 7bit
diff -rc
postgresql-jdbc-8.3-603.src.orig/org/postgresql/core/v2/ConnectionFactoryImpl.java
postgresql-jdbc-8.3-603.src/org/postgresql/core/v2/ConnectionFactoryImpl.java
***
postgresql-jdbc-8.3-603.src.orig/org/postgresql/core/v2/ConnectionFactoryImpl.java 2008-01-07
23:56:27.000000000 -0700
---
postgresql-jdbc-8.3-603.src/org/postgresql/core/v2/ConnectionFactoryImpl.java 2008-04-09
10:33:00.000000000 -0700
***************
*** 68,73 ****
--- 68,86 ----
// Construct and send an ssl startup packet if requested.
if (trySSL)
newStream = enableSSL(newStream, requireSSL, info,
logger);
+
+
+ // Set the socket timeout if the "socketTimeout" property
has been set.
+ String socketTimeoutProperty =
info.getProperty("socketTimeout", "0");
+ try {
+ int socketTimeout =
Integer.parseInt(socketTimeoutProperty);
+ if (socketTimeout > 0) {
+
newStream.getSocket().setSoTimeout(socketTimeout*1000);
+ }
+ } catch (NumberFormatException nfe) {
+ logger.info("Couldn't parse socketTimeout value:" +
socketTimeoutProperty);
+ }
+
// Construct and send a startup packet.
sendStartupPacket(newStream, user, database, logger);
diff -rc
postgresql-jdbc-8.3-603.src.orig/org/postgresql/core/v3/ConnectionFactoryImpl.java
postgresql-jdbc-8.3-603.src/org/postgresql/core/v3/ConnectionFactoryImpl.java
***
postgresql-jdbc-8.3-603.src.orig/org/postgresql/core/v3/ConnectionFactoryImpl.java 2008-01-07
23:56:27.000000000 -0700
---
postgresql-jdbc-8.3-603.src/org/postgresql/core/v3/ConnectionFactoryImpl.java 2008-04-09
10:33:00.000000000 -0700
***************
*** 79,84 ****
--- 79,95 ----
// Construct and send an ssl startup packet if requested.
if (trySSL)
newStream = enableSSL(newStream, requireSSL, info,
logger);
+
+ // Set the socket timeout if the "socketTimeout" property
has been set.
+ String socketTimeoutProperty =
info.getProperty("socketTimeout", "0");
+ try {
+ int socketTimeout =
Integer.parseInt(socketTimeoutProperty);
+ if (socketTimeout > 0) {
+
newStream.getSocket().setSoTimeout(socketTimeout*1000);
+ }
+ } catch (NumberFormatException nfe) {
+ logger.info("Couldn't parse socketTimeout value:" +
socketTimeoutProperty);
+ }
// Construct and send a startup packet.
String[][] params = {
diff -rc
postgresql-jdbc-8.3-603.src.orig/org/postgresql/ds/common/BaseDataSource.java
postgresql-jdbc-8.3-603.src/org/postgresql/ds/common/BaseDataSource.java
***
postgresql-jdbc-8.3-603.src.orig/org/postgresql/ds/common/BaseDataSource.java 2008-01-07
23:56:27.000000000 -0700
---
postgresql-jdbc-8.3-603.src/org/postgresql/ds/common/BaseDataSource.java 2008-04-09
10:33:00.000000000 -0700
***************
*** 49,57 ****
--- 49,59 ----
private int ****tNumber;
private int prepareThreshold;
private int loginTimeout; // in seconds
+ private int socketTimeout; // in seconds
private boolean ssl = false;
private String sslfactory;
+
/**
* Gets a connection to the PostgreSQL database. The database is
identified by the
* DataSource properties serverName, databaseName, and ****tNumber.
The user to
***************
*** 263,268 ****
--- 265,287 ----
}
/**
+ * Sets the socket timeout (SOTimeout), in seconds
+ */
+ public void setSocketTimeout(int seconds)
+ {
+ this.socketTimeout = seconds;
+ }
+
+ /**
+ * @[EMAIL PROTECTED]
the socket timeout (SOTimeout), in seconds
+ */
+ public int getSocketTimeout()
+ {
+ return this.socketTimeout;
+ }
+
+
+ /**
* Set whether the connection will be SSL encrypted or not.
*
* @[EMAIL PROTECTED]
enabled if <CODE>true</CODE>, connect with SSL.
***************
*** 316,321 ****
--- 335,341 ----
}
sb.append("/").append(databaseName);
sb.append("?loginTimeout=").append(loginTimeout);
+ sb.append("&socketTimeout=").append(socketTimeout);
sb.append("&prepareThreshold=").append(prepareThreshold);
if (ssl) {
sb.append("&ssl=true");
***************
*** 357,362 ****
--- 377,383 ----
ref.add(new StringRefAddr("prepareThreshold",
Integer.toString(prepareThreshold)));
ref.add(new StringRefAddr("loginTimeout",
Integer.toString(loginTimeout)));
+ ref.add(new StringRefAddr("socketTimeout",
Integer.toString(socketTimeout)));
return ref;
}
***************
*** 369,374 ****
--- 390,396 ----
out.writeInt(****tNumber);
out.writeInt(prepareThreshold);
out.writeInt(loginTimeout);
+ out.writeInt(socketTimeout);
}
protected void readBaseObject(ObjectInputStream in) throws
IOException, ClassNotFoundException
***************
*** 380,385 ****
--- 402,408 ----
****tNumber = in.readInt();
prepareThreshold = in.readInt();
loginTimeout = in.readInt();
+ socketTimeout = in.readInt();
}
}
--Apple-Mail-7--324416721
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Content-Transfer-Encoding: 7bit
Art Gramlich
Chief Application Architect
HealthTrio, LLC
art.gramlich@[EMAIL PROTECTED]
text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
--Apple-Mail-7--324416721--


|