* [ 1656849 ] WAN: every time when a query fails is tried to run locally

This commit is contained in:
Heng Sin Low 2007-02-11 16:46:43 +00:00
parent cd095c4350
commit 7a4012db51
3 changed files with 125 additions and 37 deletions

View File

@ -139,13 +139,26 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++; p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("Execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getPreparedStatement (false, null); // shared connection {
p_vo.clearParameters(); // re-use of result set log.warning("Execute locally");
ResultSet rs = ((PreparedStatement)p_stmt).executeQuery(); p_stmt = local_getPreparedStatement (false, null); // shared connection
return rs; p_vo.clearParameters(); // re-use of result set
ResultSet rs = ((PreparedStatement)p_stmt).executeQuery();
return rs;
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} // executeQuery } // executeQuery
/** /**
@ -193,15 +206,28 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
log.log(Level.SEVERE, "AppsServer not found"); log.log(Level.SEVERE, "AppsServer not found");
} }
} }
catch (RemoteException ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getPreparedStatement (false, null); // shared connection {
p_vo.clearParameters(); // re-use of result set log.warning("execute locally");
return ((PreparedStatement)p_stmt).executeUpdate(); p_stmt = local_getPreparedStatement (false, null); // shared connection
p_vo.clearParameters(); // re-use of result set
return ((PreparedStatement)p_stmt).executeUpdate();
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} // executeUpdate } // executeUpdate
/** /**
@ -877,12 +903,23 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++; p_remoteErrors++;
if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("Execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getPreparedStatement (false, null); // shared connection {
p_vo.clearParameters(); // re-use of result set log.warning("Execute locally");
return local_getRowSet(); p_stmt = local_getPreparedStatement (false, null); // shared connection
p_vo.clearParameters(); // re-use of result set
return local_getRowSet();
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} }
/** /**

View File

@ -150,15 +150,28 @@ public class CStatement implements Statement
p_remoteErrors++; p_remoteErrors++;
} }
} }
catch (RemoteException ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++; p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getStatement (false, null); // shared connection {
return p_stmt.executeQuery(p_vo.getSql()); log.warning("execute locally");
p_stmt = local_getStatement (false, null); // shared connection
return p_stmt.executeQuery(p_vo.getSql());
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} // executeQuery } // executeQuery
@ -196,15 +209,28 @@ public class CStatement implements Statement
p_remoteErrors++; p_remoteErrors++;
} }
} }
catch (RemoteException ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++; p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getStatement (false, null); // shared connection {
return p_stmt.executeUpdate(p_vo.getSql()); log.warning("execute locally");
p_stmt = local_getStatement (false, null); // shared connection
return p_stmt.executeUpdate(p_vo.getSql());
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} // executeUpdate } // executeUpdate
/** /**
@ -860,12 +886,23 @@ public class CStatement implements Statement
{ {
log.log(Level.SEVERE, "AppsServer error", ex); log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++; p_remoteErrors++;
if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
} }
// Try locally // Try locally
log.warning("Execute locally"); if (!CConnection.get().isRMIoverHTTP())
p_stmt = local_getStatement(false, null); // shared connection {
p_vo.clearParameters(); // re-use of result set log.warning("Execute locally");
return local_getRowSet(); p_stmt = local_getStatement(false, null); // shared connection
p_vo.clearParameters(); // re-use of result set
return local_getRowSet();
}
else
{
throw new IllegalStateException("WAN - Application server not available");
}
} }
/************************************************************************* /*************************************************************************

View File

@ -60,6 +60,8 @@ public final class DB
private static Connection s_connectionID = null; private static Connection s_connectionID = null;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger (DB.class); private static CLogger log = CLogger.getCLogger (DB.class);
private static Object s_ccLock = new Object();
/** SQL Statement Separator "; " */ /** SQL Statement Separator "; " */
public static final String SQLSTATEMENT_SEPARATOR = "; "; public static final String SQLSTATEMENT_SEPARATOR = "; ";
@ -228,9 +230,7 @@ public final class DB
DB.closeTarget(); DB.closeTarget();
// //
if (s_cc == null) synchronized(s_ccLock)
s_cc = cc;
synchronized (s_cc) // use as mutex
{ {
s_cc = cc; s_cc = cc;
s_connections = null; s_connections = null;
@ -239,6 +239,7 @@ public final class DB
} }
if ( isRemoteObjects() == false) if ( isRemoteObjects() == false)
s_cc.setDataSource(); s_cc.setDataSource();
log.config(s_cc + " - DS=" + s_cc.isDataSource()); log.config(s_cc + " - DS=" + s_cc.isDataSource());
// Trace.printStack(); // Trace.printStack();
} // setDBTarget } // setDBTarget
@ -249,8 +250,14 @@ public final class DB
*/ */
public static boolean connect() { public static boolean connect() {
//wan profile //wan profile
if (DB.isRemoteObjects()) return true; if (CConnection.get().isRMIoverHTTP())
return CConnection.get().isAppsServerOK(true);
//vpn profile
if (isRemoteObjects() && CConnection.get().isAppsServerOK(true))
return true;
//direct connection
boolean success =false; boolean success =false;
try try
{ {
@ -284,8 +291,14 @@ public final class DB
if (s_cc == null) return false; if (s_cc == null) return false;
//wan profile //wan profile
if (DB.isRemoteObjects()) return true; if (CConnection.get().isRMIoverHTTP())
return s_cc.isAppsServerOK(createNew);
//vpn
if (isRemoteObjects() && s_cc.isAppsServerOK(createNew))
return true;
//direct connection
boolean success = false; boolean success = false;
CLogErrorBuffer eb = CLogErrorBuffer.get(false); CLogErrorBuffer eb = CLogErrorBuffer.get(false);
if (eb != null && eb.isIssueError()) if (eb != null && eb.isIssueError())
@ -322,7 +335,7 @@ public final class DB
public static Connection getConnectionRW (boolean createNew) public static Connection getConnectionRW (boolean createNew)
{ {
//wan profile //wan profile
if (DB.isRemoteObjects()) return null; if (CConnection.get().isRMIoverHTTP()) return null;
// check health of connection // check health of connection
try try
@ -374,7 +387,7 @@ public final class DB
public static Connection getConnectionID () public static Connection getConnectionID ()
{ {
//wan profile //wan profile
if (DB.isRemoteObjects()) return null; if (CConnection.get().isRMIoverHTTP()) return null;
if (s_connectionID != null) if (s_connectionID != null)
{ {
@ -405,11 +418,11 @@ public final class DB
public static Connection getConnectionRO () public static Connection getConnectionRO ()
{ {
//wan profile //wan profile
if (DB.isRemoteObjects()) return null; if (CConnection.get().isRMIoverHTTP()) return null;
try try
{ {
synchronized (s_cc) // use as mutex as s_connection is null the first time synchronized(s_ccLock)
{ {
if (s_connections == null) if (s_connections == null)
s_connections = createConnections (Connection.TRANSACTION_READ_COMMITTED); // see below s_connections = createConnections (Connection.TRANSACTION_READ_COMMITTED); // see below
@ -485,8 +498,8 @@ public final class DB
*/ */
public static Connection createConnection (boolean autoCommit, int trxLevel) public static Connection createConnection (boolean autoCommit, int trxLevel)
{ {
//wan and vpn //wan profile
if (isRemoteObjects()) return null; if (CConnection.get().isRMIoverHTTP()) return null;
Connection conn = s_cc.getConnection (autoCommit, trxLevel); Connection conn = s_cc.getConnection (autoCommit, trxLevel);
if (CLogMgt.isLevelFinest()) if (CLogMgt.isLevelFinest())
@ -708,6 +721,7 @@ public final class DB
} }
} }
s_connections = null; s_connections = null;
// RW connection // RW connection
try try
{ {