Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Patch to add a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 1925 of 1998
Post > Topic >>

Patch to add a socketTimeout property.

by art.gramlich@[EMAIL PROTECTED] (Art Gramlich) Apr 9, 2008 at 10:52 AM

--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--
 




 13 Posts in Topic:
Patch to add a socketTimeout property.
art.gramlich@[EMAIL PROTE  2008-04-09 10:52:13 
Re: Patch to add a socketTimeout property.
shimogaki.toru@[EMAIL PRO  2008-04-10 13:36:10 
Re: Patch to add a socketTimeout property.
art.gramlich@[EMAIL PROTE  2008-04-10 09:50:55 
Re: Patch to add a socketTimeout property.
books@[EMAIL PROTECTED]   2008-04-10 14:31:26 
Re: Patch to add a socketTimeout property.
art.gramlich@[EMAIL PROTE  2008-04-10 14:59:07 
Re: Patch to add a socketTimeout property.
books@[EMAIL PROTECTED]   2008-04-10 20:51:44 
Re: Patch to add a socketTimeout property.
art.gramlich@[EMAIL PROTE  2008-04-11 10:02:53 
Re: Patch to add a socketTimeout property.
shimogaki.toru@[EMAIL PRO  2008-04-12 09:27:07 
Re: Patch to add a socketTimeout property.
books@[EMAIL PROTECTED]   2008-04-13 09:57:41 
Re: Patch to add a socketTimeout property.
oliver@[EMAIL PROTECTED]   2008-04-14 10:21:58 
Re: Patch to add a socketTimeout property.
books@[EMAIL PROTECTED]   2008-04-14 00:45:12 
Re: Patch to add a socketTimeout property.
shimogaki.toru@[EMAIL PRO  2008-04-14 14:28:28 
Re: Patch to add a socketTimeout property.
art.gramlich@[EMAIL PROTE  2008-04-14 08:49:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Thu Jul 24 13:48:47 CDT 2008.