From 90b6473b5e07ef3986fd95cafe66353f7c0cedc5 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 20 Jul 2012 21:58:09 +0200 Subject: [PATCH] Set JDBC timeouts. * src/main/java/org/glom/web/server/ConfiguredDocument.java: * src/main/java/org/glom/web/server/database/ListDBAccess.java: Set the timeout here too. --- ChangeLog | 8 ++++++++ src/main/java/org/glom/web/server/ConfiguredDocument.java | 6 ++++++ src/main/java/org/glom/web/server/database/ListDBAccess.java | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index fad7dfd..0aa446f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2012-07-20 Murray Cumming + Set JDBC timeouts. + + * src/main/java/org/glom/web/server/ConfiguredDocument.java: + * src/main/java/org/glom/web/server/database/ListDBAccess.java: + Set the timeout here too. + +2012-07-20 Murray Cumming + tests: ConfiguredDocumentTest: Make this pass. * src/test/java/org/glom/web/server/ConfiguredDocumentTest.java: diff --git a/src/main/java/org/glom/web/server/ConfiguredDocument.java b/src/main/java/org/glom/web/server/ConfiguredDocument.java index c598f58..b36ca82 100644 --- a/src/main/java/org/glom/web/server/ConfiguredDocument.java +++ b/src/main/java/org/glom/web/server/ConfiguredDocument.java @@ -21,6 +21,7 @@ package org.glom.web.server; import java.beans.PropertyVetoException; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; import java.util.Hashtable; @@ -231,6 +232,11 @@ final class ConfiguredDocument { try { // FIXME find a better way to check authentication // it's possible that the connection could be failing for another reason + + //Change the timeout, because it otherwise takes ages to fail sometimes when the details are not setup. + //This is more than enough. + DriverManager.setLoginTimeout(5); + conn = cpds.getConnection(); authenticated = true; } catch (final SQLException e) { diff --git a/src/main/java/org/glom/web/server/database/ListDBAccess.java b/src/main/java/org/glom/web/server/database/ListDBAccess.java index d20be83..23b975c 100644 --- a/src/main/java/org/glom/web/server/database/ListDBAccess.java +++ b/src/main/java/org/glom/web/server/database/ListDBAccess.java @@ -20,6 +20,7 @@ package org.glom.web.server.database; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -99,6 +100,11 @@ public abstract class ListDBAccess extends DBAccess { Statement st = null; ResultSet rs = null; try { + + //Change the timeout, because it otherwise takes ages to fail sometimes when the details are not setup. + //This is more than enough. + DriverManager.setLoginTimeout(5); + // Setup the JDBC driver and get the query. Special care needs to be take to ensure that the results will be // based on a cursor so that large amounts of memory are not consumed when the query retrieve a large amount // of data. Here's the relevant PostgreSQL documentation: @@ -155,6 +161,10 @@ public abstract class ListDBAccess extends DBAccess { Statement st = null; ResultSet rs = null; try { + //Change the timeout, because it otherwise takes ages to fail sometimes when the details are not setup. + //This is more than enough. + DriverManager.setLoginTimeout(5); + // Setup and execute the count query. Special care needs to be take to ensure that the results will be based // on a cursor so that large amounts of memory are not consumed when the query retrieve a large amount of // data. Here's the relevant PostgreSQL documentation: -- 2.1.4