diff --git a/org.adempiere.base/src/org/compiere/model/MSequence.java b/org.adempiere.base/src/org/compiere/model/MSequence.java index 1bbd5d0ac8..025caf31f8 100644 --- a/org.adempiere.base/src/org/compiere/model/MSequence.java +++ b/org.adempiere.base/src/org/compiere/model/MSequence.java @@ -127,6 +127,7 @@ public class MSequence extends X_AD_Sequence } Connection conn = null; + Statement timeoutStatement = null; PreparedStatement pstmt = null; ResultSet rs = null; for (int i = 0; i < 3; i++) @@ -145,7 +146,7 @@ public class MSequence extends X_AD_Sequence //postgresql use special syntax instead of the setQueryTimeout method if (DB.isPostgreSQL()) { - Statement timeoutStatement = conn.createStatement(); + timeoutStatement = conn.createStatement(); timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 )); } else if (DB.getDatabase().isQueryTimeoutSupported()) @@ -264,6 +265,12 @@ public class MSequence extends X_AD_Sequence DB.close(rs, pstmt); pstmt = null; rs = null; + if (timeoutStatement != null){ + try { + timeoutStatement.close(); + }catch(Exception e){} + timeoutStatement = null; + } if (conn != null) { try { @@ -378,6 +385,7 @@ public class MSequence extends X_AD_Sequence int docOrg_ID = 0; int next = -1; + Statement timeoutStatement = null; PreparedStatement pstmt = null; ResultSet rs = null; try @@ -430,7 +438,7 @@ public class MSequence extends X_AD_Sequence //postgresql use special syntax instead of the setQueryTimeout method if (DB.isPostgreSQL()) { - Statement timeoutStatement = conn.createStatement(); + timeoutStatement = conn.createStatement(); timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 )); } else if (DB.getDatabase().isQueryTimeoutSupported()) @@ -511,6 +519,10 @@ public class MSequence extends X_AD_Sequence // Finish try { + if (timeoutStatement != null) { + timeoutStatement.close(); + timeoutStatement = null; + } if (trx == null && conn != null) { conn.close(); conn = null; diff --git a/org.adempiere.base/src/org/compiere/util/DB.java b/org.adempiere.base/src/org/compiere/util/DB.java index 8f0ec3ada1..c802d3d25d 100644 --- a/org.adempiere.base/src/org/compiere/util/DB.java +++ b/org.adempiere.base/src/org/compiere/util/DB.java @@ -1101,6 +1101,7 @@ public final class DB { if (DB.isPostgreSQL()) { + Statement timeoutStatement = null; try { Connection conn = cs.getConnection(); @@ -1119,16 +1120,26 @@ public final class DB } finally { + if (rs != null) + rs.getStatement().close(); DB.close(rs); } } - Statement timeoutStatement = conn.createStatement(); + timeoutStatement = conn.createStatement(); timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( timeOut * 1000 )); if (log.isLoggable(Level.FINEST)) { log.finest("Set statement timeout to " + timeOut); } } catch (SQLException e) {} + finally{ + if (timeoutStatement != null) { + try { + timeoutStatement.close(); + } catch (Exception e) {} + timeoutStatement = null; + } + } } else { @@ -1150,7 +1161,8 @@ public final class DB { if (DB.isPostgreSQL() && timeOut > 0) { - try { + Statement timeoutStatement = null; + try { if (autoCommit) { cs.getConnection().setAutoCommit(true); @@ -1159,7 +1171,7 @@ public final class DB { if (currentTimeout > 0) { - Statement timeoutStatement = cs.getConnection().createStatement(); + timeoutStatement = cs.getConnection().createStatement(); timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( currentTimeout * 1000 )); if (log.isLoggable(Level.FINEST)) { @@ -1168,7 +1180,7 @@ public final class DB } else { - Statement timeoutStatement = cs.getConnection().createStatement(); + timeoutStatement = cs.getConnection().createStatement(); timeoutStatement.execute("SET LOCAL statement_timeout TO Default"); if (log.isLoggable(Level.FINEST)) { @@ -1179,6 +1191,14 @@ public final class DB } } catch (SQLException e) { } + finally{ + if (timeoutStatement != null) { + try { + timeoutStatement.close(); + } catch (Exception e) {} + timeoutStatement = null; + } + } } DB.close(cs); } diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java index 46853b8e4d..2488bbe053 100755 --- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java @@ -963,6 +963,8 @@ public class DB_PostgreSQL implements AdempiereDatabase } finally { + if (rs != null) + rs.getStatement().close(); DB.close(rs); }