クラス org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask

org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTaskに対する継承グラフ

Inheritance graph
[凡例]
org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTaskのコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

説明

Executes a write StoredProcedure call.

作者:
Emmanuel Cecchet
バージョン:
1.0

WriteStoredProcedureTask.java43 行で定義されています。

Public メソッド

 WriteStoredProcedureTask (int nbToComplete, int totalNb, StoredProcedure proc)
void execute (BackendWorkerThread backendThread) throws SQLException
int getResult ()
String toString ()
boolean hasTid ()
synchronized void notifySuccess ()
synchronized boolean notifyFailure (BackendWorkerThread backendThread, long timeout, SQLException e) throws SQLException
ArrayList getExceptions ()
int getFailed ()
int getNbToComplete ()
int getSuccess ()
int getTotalNb ()
void setTotalNb (int totalNb)
void setHasTid (boolean hasTid)

Private 変数

StoredProcedure proc
int result


コンストラクタとデストラクタ

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

Creates a new WriteStoredProcedureTask.

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

WriteStoredProcedureTask.java55 行で定義されています。

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


メソッド

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

Executes a write request with the given backend thread.

引数:
backendThread the backend thread that will execute the task
例外:
SQLException if an error occurs

org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTaskに実装されています.

WriteStoredProcedureTask.java68 行で定義されています。

参照先 org.objectweb.cjdbc.controller.backend.DatabaseBackend.disable(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.common.sql.AbstractRequest.getLogin(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQLShortForm(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getSQLShortFormLength(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTimeout(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTransactionId(), org.objectweb.cjdbc.common.sql.AbstractRequest.isAutoCommit, org.objectweb.cjdbc.controller.backend.DatabaseBackend.isStartedTransaction(), 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.controller.connection.AbstractConnectionManager.retrieveConnection(), と org.objectweb.cjdbc.controller.backend.DatabaseBackend.startTransaction().

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

ArrayList org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getExceptions  )  [inherited]
 

Returns the exceptions lists.

戻り値:
an ArrayList

AbstractTask.java167 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.exceptions.

00168   {
00169     return exceptions;
00170   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getFailed  )  [inherited]
 

Returns the failed.

戻り値:
an int value

AbstractTask.java177 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.failed.

参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.callStoredProcedure(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.callStoredProcedure(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.execWriteRequest(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.rollback(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.rollback(), と org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.rollback().

00178   {
00179     return failed;
00180   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getNbToComplete  )  [inherited]
 

Returns the number of threads that must succeed before returning.

戻り値:
an int value

AbstractTask.java187 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.nbToComplete.

00188   {
00189     return nbToComplete;
00190   }

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

Returns the result.

戻り値:
int

WriteStoredProcedureTask.java276 行で定義されています。

参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.execWriteStoredProcedure(), と org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.execWriteStoredProcedure().

00277   {
00278     return result;
00279   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess  )  [inherited]
 

Returns the success.

戻り値:
an int value

AbstractTask.java197 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.success.

参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.callStoredProcedure(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.callStoredProcedure(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.commit(), org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.commit(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.execWriteRequest(), org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.rollback(), org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1.rollback(), と org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0.rollback().

00198   {
00199     return success;
00200   }

int org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getTotalNb  )  [inherited]
 

Returns the total number of threads.

戻り値:
an int value
参照:
setTotalNb

AbstractTask.java208 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb.

00209   {
00210     return totalNb;
00211   }

boolean org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.hasTid  )  [inherited]
 

Returns true if this task has a tid attached to it.

Used internally by BackendWorkerThread.

戻り値:
Returns the hasTid.

AbstractTask.java231 行で定義されています。

00232   {
00233     return hasTid;
00234   }

synchronized boolean org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure BackendWorkerThread  backendThread,
long  timeout,
SQLException  e
throws SQLException [inherited]
 

Notifies that the specified backendThread failed to execute this task. If all nodes failed, this method return false meaning that the problem was due to the task and not to the thread. If the method returns true, it can mean that this thread failed and is no more coherent, therefore the backend associated to this thread should be disabled.

引数:
backendThread the backend thread that has failed
timeout time in milliseconds to wait for other threads to signal success or failure
e the exception causing the failure
戻り値:
true if at least one node succeeded to execute this task, false if all threads failed
例外:
SQLException if an error occured in the notification process

AbstractTask.java127 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.exceptions, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.failed, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.success, と org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb.

参照元 org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.execute(), と org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.kill().

00129   {
00130     failed++;
00131 
00132     // Log the exception
00133     if (exceptions == null)
00134       exceptions = new ArrayList();
00135     exceptions.add(new SQLException("BackendThread "
00136         + backendThread.getBackend().getName() + " failed (" + e + ")"));
00137 
00138     // Notify if needed
00139     if (success + failed == totalNb)
00140     {
00141       notifyAll(); // Notify all failed threads
00142     }
00143     else
00144     {
00145       try
00146       { // Wait to check if all other threads failed or not
00147         wait(timeout);
00148       }
00149       catch (InterruptedException ie)
00150       {
00151         throw new SQLException("Wait interrupted() in failed task of backend "
00152             + backendThread.getBackend().getName() + " (" + e + ")");
00153       }
00154     }
00155     return success > 0;
00156   }

synchronized void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifySuccess  )  [inherited]
 

Notifies the successful completion of this task.

AbstractTask.java96 行で定義されています。

参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.failed, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.nbToComplete, org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.success, と org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb.

参照元 org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestWithKeysTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.RollbackTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.ReadStoredProcedureTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.KillThreadTask.execute(), org.objectweb.cjdbc.controller.loadbalancer.tasks.CommitTask.execute(), と org.objectweb.cjdbc.controller.loadbalancer.tasks.BeginTask.execute().

00098   {
00099     success++;
00100 
00101     // Notify if needed
00102     if ((success == nbToComplete) || (success + failed == totalNb))
00103     {
00104       if (failed > 0)
00105         notifyAll(); // Notify all failed threads too
00106       else
00107         notify();
00108     }
00109   }

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setHasTid boolean  hasTid  )  [inherited]
 

Sets the hasTid value.

Used internally by BackendWorkerThread.

引数:
hasTid The hasTid to set.

AbstractTask.java243 行で定義されています。

参照元 org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addPriorityTask(), と org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addTask().

00244   {
00245     this.hasTid = hasTid;
00246   }

void org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.setTotalNb int  totalNb  )  [inherited]
 

Sets the total number of threads.

引数:
totalNb the total number of threads to set
参照:
getTotalNb

AbstractTask.java219 行で定義されています。

参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.callStoredProcedure().

00220   {
00221     this.totalNb = totalNb;
00222   }

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

参照:
java.lang.Object#toString()

WriteStoredProcedureTask.java284 行で定義されています。

参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL().

00285   {
00286     return "WriteStoredProcedureTask (" + proc.getSQL() + ")";
00287   }


変数

StoredProcedure org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.proc [private]
 

WriteStoredProcedureTask.java45 行で定義されています。

int org.objectweb.cjdbc.controller.loadbalancer.tasks.WriteStoredProcedureTask.result [private]
 

WriteStoredProcedureTask.java46 行で定義されています。


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0rc6に対してWed May 5 18:02:48 2004に生成されました。 doxygen 1.3.6