Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask Class Reference

Inheritance diagram for org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ReadStoredProcedureTask (int nbToComplete, int totalNb, StoredProcedure proc, MetadataCache metadataCache)
void executeTask (BackendWorkerThread backendThread) throws SQLException
ControllerResultSet getResult ()
String toString ()

Detailed Description

Executes a StoredProcedure call that returns a ResultSet.

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 47 of file ReadStoredProcedureTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.ReadStoredProcedureTask int  nbToComplete,
int  totalNb,
StoredProcedure  proc,
MetadataCache  metadataCache
 

Creates a new ReadStoredProcedureTask.

Parameters:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
proc the StoredProcedure to call
metadataCache the metadataCache if any or null

Definition at line 61 of file ReadStoredProcedureTask.java.

00063   {
00064     super(nbToComplete, totalNb);
00065     this.proc = proc;
00066     this.metadataCache = metadataCache;
00067   }


Member Function Documentation

void org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.executeTask BackendWorkerThread  backendThread  )  throws SQLException [virtual]
 

Call a stored procedure that returns a ResultSet on the given backend thread.

Parameters:
backendThread the backend thread that will execute the task
Exceptions:
SQLException if an error occurs

Implements org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.

Definition at line 76 of file ReadStoredProcedureTask.java.

References org.objectweb.cjdbc.common.log.Trace.error(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionForTransactionAndLazyBeginIfNeeded(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getSQLShortFormLength(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess(), and org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection().

00078   {
00079     DatabaseBackend backend = backendThread.getBackend();
00080 
00081     AbstractConnectionManager cm = backend
00082         .getConnectionManager(proc.getLogin());
00083     if (cm == null)
00084     {
00085       SQLException se = new SQLException(
00086           "No Connection Manager for Virtual Login:" + proc.getLogin());
00087       try
00088       {
00089         notifyFailure(backendThread, 1, se);
00090       }
00091       catch (SQLException ignore)
00092       {
00093 
00094       }
00095       throw se;
00096     }
00097 
00098     Trace logger = backendThread.getLogger();
00099     if (proc.isAutoCommit())
00100     { // Use a connection just for this request
00101       Connection c = null;
00102       try
00103       {
00104         c = cm.getConnection();
00105       }
00106       catch (UnreachableBackendException e1)
00107       {
00108         SQLException se = new SQLException("Backend " + backend.getName()
00109             + " is no more reachable.");
00110         try
00111         {
00112           notifyFailure(backendThread, 1, se);
00113         }
00114         catch (SQLException ignore)
00115         {
00116         }
00117         // Disable this backend (it is no more in sync) by killing the backend
00118         // thread
00119         backendThread.kill();
00120         logger.error("Disabling backend " + backend.getName()
00121             + " because it is no more reachable.");
00122         throw se;
00123       }
00124 
00125       // Sanity check
00126       if (c == null)
00127       {
00128         SQLException se = new SQLException("No more connections");
00129         try
00130         { // All backends failed, just ignore
00131           if (!notifyFailure(backendThread, (long) proc.getTimeout() * 1000, se))
00132             return;
00133         }
00134         catch (SQLException ignore)
00135         {
00136         }
00137         // Disable this backend (it is no more in sync) by killing the backend
00138         // thread
00139         backendThread.kill();
00140         String msg = "Stored procedure '"
00141             + proc.getSQLShortForm(backend.getSQLShortFormLength())
00142             + "' failed on backend " + backend.getName() + " but "
00143             + getSuccess() + " succeeded (" + se + ")";
00144         logger.error(msg);
00145         throw new SQLException(msg);
00146       }
00147 
00148       // Execute Query
00149       try
00150       {
00151         result = AbstractLoadBalancer.executeReadStoredProcedureOnBackend(proc,
00152             backend, c, metadataCache);
00153       }
00154       catch (Exception e)
00155       {
00156         try
00157         { // All backends failed, just ignore
00158           if (!notifyFailure(backendThread, (long) proc.getTimeout() * 1000, e))
00159             return;
00160         }
00161         catch (SQLException ignore)
00162         {
00163         }
00164         // Disable this backend (it is no more in sync) by killing the backend
00165         // thread
00166         backendThread.kill();
00167         String msg = "Stored procedure '"
00168             + proc.getSQLShortForm(backend.getSQLShortFormLength())
00169             + "' failed on backend " + backend.getName() + " but "
00170             + getSuccess() + " succeeded (" + e + ")";
00171         logger.error(msg);
00172         throw new SQLException(msg);
00173       }
00174       finally
00175       {
00176         cm.releaseConnection(c);
00177       }
00178     }
00179     else
00180     { // Re-use the connection used by this transaction
00181       Connection c;
00182       long tid = proc.getTransactionId();
00183       Long lTid = new Long(tid);
00184 
00185       try
00186       {
00187         c = backend.getConnectionForTransactionAndLazyBeginIfNeeded(lTid, cm);
00188       }
00189       catch (UnreachableBackendException ube)
00190       {
00191         SQLException se = new SQLException("Backend " + backend.getName()
00192             + " is no more reachable.");
00193         try
00194         {
00195           notifyFailure(backendThread, 1, se);
00196         }
00197         catch (SQLException ignore)
00198         {
00199         }
00200         // Disable this backend (it is no more in sync) by killing the backend
00201         // thread
00202         backendThread.kill();
00203         logger.error("Disabling backend " + backend.getName()
00204             + " because it is no more reachable.");
00205         throw se;
00206       }
00207       catch (NoTransactionStartWhenDisablingException e)
00208       {
00209         logger
00210             .error("Disabling backend "
00211                 + backend.getName()
00212                 + " has been assigned a select request but it cannot start a new transaction for it.");
00213         notifyFailure(backendThread, (long) proc.getTimeout() * 1000, e);
00214         return;
00215       }
00216       catch (SQLException e1)
00217       {
00218         SQLException se = new SQLException(
00219             "Unable to get connection for transaction " + tid);
00220         try
00221         { // All backends failed, just ignore
00222           if (!notifyFailure(backendThread, (long) proc.getTimeout() * 1000, se))
00223             return;
00224         }
00225         catch (SQLException ignore)
00226         {
00227         }
00228         // Disable this backend (it is no more in sync) by killing the
00229         // backend thread
00230         backendThread.kill();
00231         String msg = "Request '"
00232             + proc.getSQLShortForm(backend.getSQLShortFormLength())
00233             + "' failed on backend " + backend.getName() + " but "
00234             + getSuccess() + " succeeded (" + se + ")";
00235         logger.error(msg);
00236         throw new SQLException(msg);
00237       }
00238 
00239       // Sanity check
00240       if (c == null)
00241       { // Bad connection
00242         SQLException se = new SQLException(
00243             "Unable to retrieve connection for transaction " + tid);
00244         try
00245         { // All backends failed, just ignore
00246           if (!notifyFailure(backendThread, (long) proc.getTimeout() * 1000, se))
00247             return;
00248         }
00249         catch (SQLException ignore)
00250         {
00251         }
00252         // Disable this backend (it is no more in sync) by killing the
00253         // backend thread
00254         backendThread.kill();
00255         String msg = "Request '"
00256             + proc.getSQLShortForm(backend.getSQLShortFormLength())
00257             + "' failed on backend " + backend.getName() + " but "
00258             + getSuccess() + " succeeded (" + se + ")";
00259         logger.error(msg);
00260         throw new SQLException(msg);
00261       }
00262 
00263       // Execute Query
00264       try
00265       {
00266         result = AbstractLoadBalancer.executeReadStoredProcedureOnBackend(proc,
00267             backend, c, metadataCache);
00268 
00269         // Warning! No way to detect if schema has been modified unless
00270         // we ask the backend again using DatabaseMetaData.getTables().
00271       }
00272       catch (Exception e)
00273       {
00274         try
00275         { // All backends failed, just ignore
00276           if (!notifyFailure(backendThread, (long) proc.getTimeout() * 1000, e))
00277             return;
00278         }
00279         catch (SQLException ignore)
00280         {
00281         }
00282         // Disable this backend (it is no more in sync) by killing the backend
00283         // thread
00284         backendThread.kill();
00285         String msg = "Stored procedure '"
00286             + proc.getSQLShortForm(backend.getSQLShortFormLength())
00287             + "' failed on backend " + backend.getName() + " but "
00288             + getSuccess() + " succeeded (" + e + ")";
00289         logger.error(msg);
00290         throw new SQLException(msg);
00291       }
00292     }
00293     notifySuccess();
00294   }

ControllerResultSet org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.getResult  ) 
 

Returns the result.

Returns:
a ResultSet

Definition at line 301 of file ReadStoredProcedureTask.java.

Referenced by org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.execReadStoredProcedure(), and org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.execReadStoredProcedure().

00302   {
00303     return result;
00304   }

String org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.toString  ) 
 

See also:
java.lang.Object#toString()

Definition at line 309 of file ReadStoredProcedureTask.java.

00310   {
00311     return "ReadStoredProcedureTask (" + proc.getSQL() + ")";
00312   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:04:17 2005 for C-JDBC by  doxygen 1.3.9.1