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

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

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

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WriteStoredProcedureTask (int nbToComplete, int totalNb, StoredProcedure proc)
void executeTask (BackendWorkerThread backendThread) throws SQLException
int getResult ()
String toString ()

Detailed Description

Executes a write StoredProcedure call.

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 44 of file WriteStoredProcedureTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.WriteStoredProcedureTask int  nbToComplete,
int  totalNb,
StoredProcedure  proc
 

Creates a new WriteStoredProcedureTask.

Parameters:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
proc the StoredProcedure to call

Definition at line 56 of file WriteStoredProcedureTask.java.

00058   {
00059     super(nbToComplete, totalNb);
00060     this.proc = proc;
00061   }


Member Function Documentation

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

Executes a write request with 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 69 of file WriteStoredProcedureTask.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.backend.DatabaseBackend.isDisabling(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyCompletion(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess(), and org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection().

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

int org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.getResult  ) 
 

Returns the result.

Returns:
int

Definition at line 298 of file WriteStoredProcedureTask.java.

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

00299   {
00300     return result;
00301   }

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

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

Definition at line 306 of file WriteStoredProcedureTask.java.

00307   {
00308     if (proc.isAutoCommit())
00309       return "Write autocommit StoredProcedureTask (" + proc.getSQL() + ")";
00310     else
00311       return "Write StoredProcedureTask for transaction:"
00312           + proc.getTransactionId() + "(" + proc.getSQL() + ")";
00313   }


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