IDEMPIERE-1206 Drop obsolete QueryTimeout workaround for PostgreSQL JDBC Driver.

This commit is contained in:
Heng Sin Low 2013-07-29 15:36:46 +08:00
parent 194cd9f05e
commit 3c80de243c
5 changed files with 4 additions and 165 deletions

View File

@ -322,15 +322,6 @@ public interface AdempiereDatabase
*/
public String addPagingSQL(String sql, int start, int end);
/**
* set statement/query timeout for connection
* @param conn
* @param timeout
* @return original timeout setting
* @throws SQLException
*/
public int setStatementTimeout(Connection conn, int timeout) throws SQLException;
/**
* Lock PO for update
* @param po

View File

@ -143,13 +143,7 @@ public class MSequence extends X_AD_Sequence
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1, TableName);
//
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
timeoutStatement = conn.createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 ));
}
else if (DB.getDatabase().isQueryTimeoutSupported())
if (DB.getDatabase().isQueryTimeoutSupported())
{
pstmt.setQueryTimeout(QUERY_TIME_OUT);
}
@ -434,13 +428,7 @@ public class MSequence extends X_AD_Sequence
}
//
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
timeoutStatement = conn.createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 ));
}
else if (DB.getDatabase().isQueryTimeoutSupported())
if (DB.getDatabase().isQueryTimeoutSupported())
{
pstmt.setQueryTimeout(QUERY_TIME_OUT);
}

View File

@ -1017,17 +1017,13 @@ public final class DB
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
int currentTimeout = -1;
try
{
setParameters(cs, params);
//set timeout
if (timeOut > 0)
{
if (DB.isPostgreSQL())
currentTimeout = DB.getDatabase().setStatementTimeout(cs.getConnection(), timeOut);
else
cs.setQueryTimeout(timeOut);
cs.setQueryTimeout(timeOut);
}
no = cs.executeUpdate();
// No Transaction - Commit
@ -1050,14 +1046,6 @@ public final class DB
}
finally
{
if (DB.isPostgreSQL() && timeOut > 0)
{
try
{
DB.getDatabase().setStatementTimeout(cs.getConnection(), currentTimeout);
}
catch (SQLException e) {}
}
// Always close cursor
close(cs);
cs = null;
@ -1097,52 +1085,11 @@ public final class DB
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
boolean autoCommit = false;
int currentTimeout = 0;
try
{
autoCommit = cs.getConnection().getAutoCommit();
setParameters(cs, params);
if (timeOut > 0)
{
if (DB.isPostgreSQL())
{
Statement timeoutStatement = null;
try
{
Connection conn = cs.getConnection();
if (autoCommit)
{
conn.setAutoCommit(false);
}
else
{
ResultSet rs = null;
try
{
rs = conn.createStatement().executeQuery("select current_setting('statement_timeout')");
if (rs.next())
currentTimeout = rs.getInt(1);
}
finally
{
close(rs.getStatement());
close(rs);rs = null;
}
}
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{
DB.close(timeoutStatement);
timeoutStatement = null;
}
}
else
{
cs.setQueryTimeout(timeOut);
}
@ -1160,43 +1107,6 @@ public final class DB
}
finally
{
if (DB.isPostgreSQL() && timeOut > 0)
{
Statement timeoutStatement = null;
try {
if (autoCommit)
{
cs.getConnection().setAutoCommit(true);
}
else
{
if (currentTimeout > 0)
{
timeoutStatement = cs.getConnection().createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( currentTimeout * 1000 ));
if (log.isLoggable(Level.FINEST))
{
log.finest("Reset statement timeout to " + currentTimeout);
}
}
else
{
timeoutStatement = cs.getConnection().createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO Default");
if (log.isLoggable(Level.FINEST))
{
log.finest("Reset statement timeout to default");
}
}
}
} catch (SQLException e) {
}
finally{
close(timeoutStatement);
timeoutStatement = null;
}
}
close(cs);
cs = null;
}

View File

@ -1319,12 +1319,6 @@ public class DB_Oracle implements AdempiereDatabase
return b;
}
@Override
public int setStatementTimeout(Connection conn, int timeout) throws SQLException {
//not supported by oracle
return -1;
}
@Override
public boolean forUpdate(PO po, int timeout) {
//only can lock for update if using trx

View File

@ -1036,46 +1036,6 @@ public class DB_PostgreSQL implements AdempiereDatabase
return b;
}
@Override
public int setStatementTimeout(Connection conn, int timeOut) throws SQLException {
int currentTimeout = 0;
boolean autoCommit = conn.getAutoCommit();
ResultSet rs = null;
try
{
rs = conn.createStatement().executeQuery("select extract(epoch from current_setting('statement_timeout')::interval)*1000");
if (rs.next()) {
currentTimeout = rs.getInt(1) / 1000;
}
}
finally
{
if (rs != null)
DB.close(rs.getStatement());
DB.close(rs);
rs = null;
}
Statement timeoutStatement = null;
try
{
timeoutStatement = conn.createStatement();
String sql = "SET " + (autoCommit ? "SESSION" : "LOCAL") + " statement_timeout TO " + ( timeOut > 0 ? Integer.toString(timeOut * 1000) : " DEFAULT ");
timeoutStatement.execute(sql);
}
finally
{
DB.close(timeoutStatement);
timeoutStatement = null;
}
if (log.isLoggable(Level.FINEST))
{
log.finest("Set statement timeout to " + timeOut);
}
return currentTimeout;
}
@Override
public boolean forUpdate(PO po, int timeout) {
//only can lock for update if using trx
@ -1110,14 +1070,13 @@ public class DB_PostgreSQL implements AdempiereDatabase
PreparedStatement stmt = null;
ResultSet rs = null;
int currentTimeout = -1;
try {
stmt = DB.prepareStatement(sqlBuffer.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, po.get_TrxName());
for(int i = 0; i < keyColumns.length; i++) {
stmt.setObject(i+1, parameters[i]);
}
currentTimeout = setStatementTimeout(stmt.getConnection(), (timeout > 0 ? timeout : LOCK_TIME_OUT));
stmt.setQueryTimeout(timeout > 0 ? timeout : LOCK_TIME_OUT);
rs = stmt.executeQuery();
if (rs.next()) {
@ -1129,9 +1088,6 @@ public class DB_PostgreSQL implements AdempiereDatabase
if (log.isLoggable(Level.INFO))log.log(Level.INFO, e.getLocalizedMessage(), e);
throw new DBException("Could not lock record for " + po.toString() + " caused by " + e.getLocalizedMessage());
} finally {
try {
if(stmt!=null)setStatementTimeout(stmt.getConnection(), currentTimeout);
} catch (SQLException e) {}
DB.close(rs, stmt);
rs = null;stmt = null;
}