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

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

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

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WriteRequestWithKeysTask (int nbToComplete, int totalNb, AbstractWriteRequest request, MetadataCache metadataCache)
void executeTask (BackendWorkerThread backendThread) throws SQLException
ControllerResultSet getResult ()
String toString ()

Detailed Description

Executes a AbstractWriteRequest statement and return the auto generated keys.

Author:
Emmanuel Cecchet

Jaco Swart

Version:
1.0

Definition at line 53 of file WriteRequestWithKeysTask.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.WriteRequestWithKeysTask int  nbToComplete,
int  totalNb,
AbstractWriteRequest  request,
MetadataCache  metadataCache
 

Creates a new WriteRequestTask.

Parameters:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
request an AbstractWriteRequest
metadataCache the metadataCache if any or null

Definition at line 67 of file WriteRequestWithKeysTask.java.

00069   {
00070     super(nbToComplete, totalNb);
00071     this.request = request;
00072     this.metadataCache = metadataCache;
00073   }


Member Function Documentation

void org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.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 81 of file WriteRequestWithKeysTask.java.

References org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.addTable(), org.objectweb.cjdbc.common.log.Trace.debug(), 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.getDatabaseSchema(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDriverCompliance(), 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.common.sql.schema.DatabaseSchema.getTable(), org.objectweb.cjdbc.common.log.Trace.isDebugEnabled(), 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(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.releaseConnection(), org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.removeTable(), and org.objectweb.cjdbc.controller.backend.DriverCompliance.supportGetGeneratedKeys.

00083   {
00084     DatabaseBackend backend = backendThread.getBackend();
00085 
00086     if (!backend.getDriverCompliance().supportGetGeneratedKeys())
00087       throw new SQLException(Translate.get(
00088           "loadbalancer.backend.autogeneratedkeys.unsupported", backend
00089               .getName()));
00090 
00091     AbstractConnectionManager cm = backend.getConnectionManager(request
00092         .getLogin());
00093     if (cm == null)
00094     {
00095       SQLException se = new SQLException(
00096           "No Connection Manager for Virtual Login:" + request.getLogin());
00097       try
00098       {
00099         notifyFailure(backendThread, 1, se);
00100       }
00101       catch (SQLException ignore)
00102       {
00103 
00104       }
00105       throw se;
00106     }
00107 
00108     Trace logger = backendThread.getLogger();
00109     if (request.isAutoCommit())
00110     {
00111       if (backend.isDisabling())
00112       {
00113         // Backend is disabling, we do not start new transactions, just notify
00114         // the completion for the others
00115         notifyCompletion();
00116         return;
00117       }
00118 
00119       // Use a connection just for this request
00120       Connection c = null;
00121       try
00122       {
00123         c = cm.getConnection();
00124       }
00125       catch (UnreachableBackendException e1)
00126       {
00127         SQLException se = new SQLException("Backend " + backend.getName()
00128             + " is no more reachable.");
00129         try
00130         {
00131           notifyFailure(backendThread, 1, se);
00132         }
00133         catch (SQLException ignore)
00134         {
00135         }
00136         // Disable this backend (it is no more in sync) by killing the backend
00137         // thread
00138         backendThread.kill();
00139         logger.error("Disabling backend " + backend.getName()
00140             + " because it is no more reachable.");
00141         throw se;
00142       }
00143 
00144       // Sanity check
00145       if (c == null)
00146       {
00147         SQLException se = new SQLException("No more connections");
00148         try
00149         { // All backends failed, just ignore
00150           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00151               se))
00152             return;
00153         }
00154         catch (SQLException ignore)
00155         {
00156         }
00157         // Disable this backend (it is no more in sync) by killing the backend
00158         // thread
00159         backendThread.kill();
00160         String msg = "Request '"
00161             + request.getSQLShortForm(backend.getSQLShortFormLength())
00162             + "' failed on backend " + backend.getName() + " but "
00163             + getSuccess() + " succeeded (" + se + ")";
00164         logger.error(msg);
00165         throw new SQLException(msg);
00166       }
00167 
00168       // Execute Query
00169       try
00170       {
00171         result = AbstractLoadBalancer.executeUpdateRequestOnBackendWithKeys(
00172             request, backend, c, metadataCache);
00173 
00174         // Update schema
00175         if (request.isCreate())
00176         { // Add the table to the schema
00177           DatabaseSchema dbs = backend.getDatabaseSchema();
00178           if (dbs != null)
00179           {
00180             DatabaseTable t = ((CreateRequest) request).getDatabaseTable();
00181             if (t != null)
00182             {
00183               dbs.addTable(t);
00184               if (logger.isDebugEnabled())
00185                 logger.debug("Added table '" + request.getTableName()
00186                     + "' to backend database schema");
00187             }
00188           }
00189         }
00190         else if (request.isDrop())
00191         { // Delete the table from the schema
00192           DatabaseSchema dbs = backend.getDatabaseSchema();
00193           if (dbs != null)
00194           {
00195             DatabaseTable t = dbs.getTable(request.getTableName());
00196             if (t != null)
00197             {
00198               dbs.removeTable(t);
00199               if (logger.isDebugEnabled())
00200                 logger.debug("Removed table '" + request.getTableName()
00201                     + "' from backend database schema");
00202             }
00203           }
00204         }
00205       }
00206       catch (Exception e)
00207       {
00208         try
00209         { // All backends failed, just ignore
00210           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00211               e))
00212             return;
00213         }
00214         catch (SQLException ignore)
00215         {
00216         }
00217         // Disable this backend (it is no more in sync) by killing the backend
00218         // thread
00219         backendThread.kill();
00220         String msg = "Request '"
00221             + request.getSQLShortForm(backend.getSQLShortFormLength())
00222             + "' failed on backend " + backend.getName() + " but "
00223             + getSuccess() + " succeeded (" + e + ")";
00224         logger.error(msg);
00225         throw new SQLException(msg);
00226       }
00227       finally
00228       {
00229         cm.releaseConnection(c);
00230       }
00231     }
00232     else
00233     { // Re-use the connection used by this transaction
00234       Connection c;
00235       long tid = request.getTransactionId();
00236       Long lTid = new Long(tid);
00237 
00238       try
00239       {
00240         c = backend.getConnectionForTransactionAndLazyBeginIfNeeded(lTid, cm);
00241       }
00242       catch (UnreachableBackendException ube)
00243       {
00244         SQLException se = new SQLException("Backend " + backend.getName()
00245             + " is no more reachable.");
00246         try
00247         {
00248           notifyFailure(backendThread, 1, se);
00249         }
00250         catch (SQLException ignore)
00251         {
00252         }
00253         // Disable this backend (it is no more in sync) by killing the backend
00254         // thread
00255         backendThread.kill();
00256         logger.error("Disabling backend " + backend.getName()
00257             + " because it is no more reachable.");
00258         throw se;
00259       }
00260       catch (NoTransactionStartWhenDisablingException e)
00261       {
00262         // Backend is disabling, we do not execute queries except the one in the
00263         // transaction we already started. Just notify the completion for the
00264         // others.
00265         notifyCompletion();
00266         return;
00267       }
00268       catch (SQLException e1)
00269       {
00270         SQLException se = new SQLException(
00271             "Unable to get connection for transaction " + tid);
00272         try
00273         { // All backends failed, just ignore
00274           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00275               se))
00276             return;
00277         }
00278         catch (SQLException ignore)
00279         {
00280         }
00281         // Disable this backend (it is no more in sync) by killing the
00282         // backend thread
00283         backendThread.kill();
00284         String msg = "Request '"
00285             + request.getSQLShortForm(backend.getSQLShortFormLength())
00286             + "' failed on backend " + backend.getName() + " but "
00287             + getSuccess() + " succeeded (" + se + ")";
00288         logger.error(msg);
00289         throw new SQLException(msg);
00290       }
00291 
00292       // Sanity check
00293       if (c == null)
00294       { // Bad connection
00295         SQLException se = new SQLException(
00296             "Unable to retrieve connection for transaction " + tid);
00297         try
00298         { // All backends failed, just ignore
00299           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00300               se))
00301             return;
00302         }
00303         catch (SQLException ignore)
00304         {
00305         }
00306         // Disable this backend (it is no more in sync) by killing the
00307         // backend thread
00308         backendThread.kill();
00309         String msg = "Request '"
00310             + request.getSQLShortForm(backend.getSQLShortFormLength())
00311             + "' failed on backend " + backend.getName() + " but "
00312             + getSuccess() + " succeeded (" + se + ")";
00313         logger.error(msg);
00314         throw new SQLException(msg);
00315       }
00316 
00317       // Execute Query
00318       try
00319       {
00320         result = AbstractLoadBalancer.executeUpdateRequestOnBackendWithKeys(
00321             request, backend, c, metadataCache);
00322 
00323         // Update schema
00324         if (request.isCreate())
00325         { // Add the table to the schema
00326           DatabaseSchema dbs = backend.getDatabaseSchema();
00327           if (dbs != null)
00328           {
00329             DatabaseTable t = ((CreateRequest) request).getDatabaseTable();
00330             if (t != null)
00331             {
00332               dbs.addTable(t);
00333               if (logger.isDebugEnabled())
00334                 logger.debug("Added table '" + request.getTableName()
00335                     + "' to backend database schema");
00336             }
00337           }
00338         }
00339         else if (request.isDrop())
00340         { // Delete the table from the schema
00341           DatabaseSchema dbs = backend.getDatabaseSchema();
00342           if (dbs != null)
00343           {
00344             DatabaseTable t = dbs.getTable(request.getTableName());
00345             if (t != null)
00346             {
00347               dbs.removeTable(t);
00348               if (logger.isDebugEnabled())
00349                 logger.debug("Removed table '" + request.getTableName()
00350                     + "' from backend database schema");
00351             }
00352           }
00353         }
00354       }
00355       catch (Exception e)
00356       {
00357         try
00358         { // All backends failed, just ignore
00359           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00360               e))
00361             return;
00362         }
00363         catch (SQLException ignore)
00364         {
00365         }
00366         // Disable this backend (it is no more in sync) by killing the backend
00367         // thread
00368         backendThread.kill();
00369         String msg = "Request '"
00370             + request.getSQLShortForm(backend.getSQLShortFormLength())
00371             + "' failed on backend " + backend.getName() + " but "
00372             + getSuccess() + " succeeded (" + e + ")";
00373         logger.error(msg);
00374         throw new SQLException(msg);
00375       }
00376     }
00377     notifySuccess();
00378   }

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

Returns the auto generated keys.

Returns:
ResultSet

Definition at line 385 of file WriteRequestWithKeysTask.java.

00386   {
00387     return result;
00388   }

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

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

Definition at line 393 of file WriteRequestWithKeysTask.java.

00394   {
00395     if (request.isAutoCommit())
00396       return "WriteWithKeys  Autocommit Task (" + request.getSQL() + ")";
00397     else
00398       return "WriteWithKeys Task from transaction:"
00399           + request.getTransactionId() + "(" + request.getSQL() + ")";
00400   }


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