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

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

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

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

説明

Executes a SELECT statement.

作者:
Emmanuel Cecchet

Julie Marguerite

バージョン:
1.0

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

Public メソッド

 SelectRequestTask (int nbToComplete, int totalNb, SelectRequest request)
void execute (BackendWorkerThread backendThread) throws SQLException
ResultSet 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 変数

SelectRequest request
ResultSet result


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

org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.SelectRequestTask int  nbToComplete,
int  totalNb,
SelectRequest  request
 

Creates a new WriteRequestTask instance.

引数:
nbToComplete number of threads that must succeed before returning
totalNb total number of threads
request an AbstractWriteRequest

SelectRequestTask.java58 行で定義されています。

00059   {
00060     super(nbToComplete, totalNb);
00061     this.request = request;
00062   }


メソッド

void org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.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に実装されています.

SelectRequestTask.java70 行で定義されています。

参照先 org.objectweb.cjdbc.controller.backend.DatabaseBackend.disable(), java.sql.Statement.executeQuery(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDriverCompliance(), org.objectweb.cjdbc.common.sql.AbstractRequest.getMaxRows(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQLShortForm(), 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.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.rewriteQuery(), java.sql.Statement.setMaxRows(), java.sql.Statement.setQueryTimeout(), org.objectweb.cjdbc.controller.backend.DriverCompliance.supportSetMaxRows, と org.objectweb.cjdbc.controller.backend.DriverCompliance.supportSetQueryTimeout.

00071   {
00072     DatabaseBackend backend = backendThread.getBackend();
00073 
00074     AbstractConnectionManager cm = backend.getConnectionManager(request
00075         .getLogin());
00076     if (request.isAutoCommit())
00077     { // Use a connection just for this request
00078       Connection c = null;
00079       try
00080       {
00081         c = cm.getConnection();
00082       }
00083       catch (UnreachableBackendException e1)
00084       {
00085         backendThread.getLogger().error(
00086             "Disabling backend " + backend.getName()
00087                 + " because it is no more reachable.");
00088         backend.disable();
00089         throw new SQLException("Backend " + backend.getName()
00090             + " is no more reachable.");
00091       }
00092 
00093       // Sanity check
00094       if (c == null)
00095       {
00096         SQLException se = new SQLException("No more connections");
00097         try
00098         { // All backends failed, just ignore
00099           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00100               se))
00101             return;
00102         }
00103         catch (SQLException ignore)
00104         {
00105         }
00106         // Disable this backend (it is no more in sync) by killing the backend
00107         // thread
00108         backendThread.kill();
00109         throw new SQLException("Request '"
00110             + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
00111             + "' failed on backend " + backend.getName() + " (" + se + ")");
00112       }
00113 
00114       // Execute Query
00115       try
00116       {
00117         Statement s = c.createStatement();
00118         if (backend.getDriverCompliance().supportSetQueryTimeout())
00119           s.setQueryTimeout(request.getTimeout());
00120         if ((request.getMaxRows() > 0)
00121             && backend.getDriverCompliance().supportSetMaxRows())
00122           s.setMaxRows(request.getMaxRows());
00123 
00124         String sql = request.getSQL();
00125         // Rewrite the query if needed
00126         sql = backend.rewriteQuery(sql);
00127         result = s.executeQuery(sql);
00128       }
00129       catch (SQLException e)
00130       {
00131         try
00132         { // All backends failed, just ignore
00133           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00134               e))
00135             return;
00136         }
00137         catch (SQLException ignore)
00138         {
00139         }
00140         throw new SQLException("Request '"
00141             + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
00142             + "' failed on backend " + backend.getName() + " (" + e + ")");
00143       }
00144       finally
00145       {
00146         cm.releaseConnection(c);
00147       }
00148     }
00149     else
00150     { // Re-use the connection used by this transaction
00151       Connection c = cm.retrieveConnection(request.getTransactionId());
00152 
00153       // Sanity check
00154       if (c == null)
00155       { // Bad connection
00156         SQLException se = new SQLException(
00157             "Unable to retrieve connection for transaction "
00158                 + request.getTransactionId());
00159         try
00160         { // All backends failed, just ignore
00161           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00162               se))
00163             return;
00164         }
00165         catch (SQLException ignore)
00166         {
00167         }
00168         throw new SQLException("Request '"
00169             + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
00170             + "' failed on backend " + backend.getName() + " (" + se + ")");
00171       }
00172 
00173       // Execute Query
00174       try
00175       {
00176         Statement s = c.createStatement();
00177         if (backend.getDriverCompliance().supportSetQueryTimeout())
00178           s.setQueryTimeout(request.getTimeout());
00179         if ((request.getMaxRows() > 0)
00180             && backend.getDriverCompliance().supportSetMaxRows())
00181           s.setMaxRows(request.getMaxRows());
00182 
00183         String sql = request.getSQL();
00184         // Rewrite the query if needed
00185         sql = backend.rewriteQuery(sql);
00186         result = s.executeQuery(sql);
00187       }
00188       catch (SQLException e)
00189       {
00190         try
00191         { // All backends failed, just ignore
00192           if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000,
00193               e))
00194             return;
00195         }
00196         catch (SQLException ignore)
00197         {
00198         }
00199         throw new SQLException("Request '"
00200             + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)
00201             + "' failed on backend " + backend.getName() + " (" + e + ")");
00202       }
00203     }
00204     notifySuccess();
00205   }

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   }

ResultSet org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.getResult  ) 
 

Returns the result.

戻り値:
a ResultSet

SelectRequestTask.java212 行で定義されています。

00213   {
00214     return result;
00215   }

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.SelectRequestTask.toString  ) 
 

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

SelectRequestTask.java220 行で定義されています。

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

00221   {
00222     return "SelectRequestTask (" + request.getSQL() + ")";
00223   }


変数

SelectRequest org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.request [private]
 

SelectRequestTask.java48 行で定義されています。

ResultSet org.objectweb.cjdbc.controller.loadbalancer.tasks.SelectRequestTask.result [private]
 

SelectRequestTask.java49 行で定義されています。


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