AbstractWriteRequest
statement and return the auto generated keys.
WriteRequestWithKeysTask.java の 49 行で定義されています。
Public メソッド | |
WriteRequestWithKeysTask (int nbToComplete, int totalNb, AbstractWriteRequest 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 変数 | |
AbstractWriteRequest | request |
ResultSet | result |
|
Creates a new
WriteRequestWithKeysTask.java の 61 行で定義されています。
00063 {
00064 super(nbToComplete, totalNb);
00065 this.request = request;
00066 }
|
|
Executes a write request with the given backend thread.
org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTaskに実装されています. WriteRequestWithKeysTask.java の 74 行で定義されています。 参照先 org.objectweb.cjdbc.common.sql.schema.DatabaseSchema.addTable(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.disable(), java.sql.Statement.executeUpdate(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.getConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDatabaseSchema(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getDriverCompliance(), java.sql.Statement.getGeneratedKeys(), org.objectweb.cjdbc.common.sql.AbstractRequest.getId(), 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.schema.DatabaseSchema.getTable(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getTableName(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTimeout(), org.objectweb.cjdbc.common.sql.AbstractRequest.getTransactionId(), org.objectweb.cjdbc.common.sql.AbstractRequest.isAutoCommit, org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isCreate(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isDrop(), 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.common.sql.schema.DatabaseSchema.removeTable(), org.objectweb.cjdbc.controller.connection.AbstractConnectionManager.retrieveConnection(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.rewriteQuery(), java.sql.Statement.setQueryTimeout(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.startTransaction(), org.objectweb.cjdbc.controller.backend.DriverCompliance.supportGetGeneratedKeys, と org.objectweb.cjdbc.controller.backend.DriverCompliance.supportSetQueryTimeout.
00075 { 00076 DatabaseBackend backend = backendThread.getBackend(); 00077 00078 if (!backend.getDriverCompliance().supportGetGeneratedKeys()) 00079 throw new SQLException(Translate.get( 00080 "loadbalancer.backend.autogeneratedkeys.unsupported", backend 00081 .getName())); 00082 00083 AbstractConnectionManager cm = backend.getConnectionManager(request 00084 .getLogin()); 00085 00086 if (request.isAutoCommit()) 00087 { // Use a connection just for this request 00088 Connection c = null; 00089 try 00090 { 00091 c = cm.getConnection(); 00092 } 00093 catch (UnreachableBackendException e1) 00094 { 00095 backendThread.getLogger().error( 00096 "Disabling backend " + backend.getName() 00097 + " because it is no more reachable."); 00098 backend.disable(); 00099 throw new SQLException("Backend " + backend.getName() 00100 + " is no more reachable."); 00101 } 00102 00103 // Sanity check 00104 if (c == null) 00105 { 00106 SQLException se = new SQLException("No more connections"); 00107 try 00108 { // All backends failed, just ignore 00109 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00110 se)) 00111 return; 00112 } 00113 catch (SQLException ignore) 00114 { 00115 } 00116 // Disable this backend (it is no more in sync) by killing the backend 00117 // thread 00118 backendThread.kill(); 00119 String msg = "Request '" 00120 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00121 + "' failed on backend " + backend.getName() + " but " 00122 + getSuccess() + " succeeded (" + se + ")"; 00123 backendThread.getLogger().error(msg); 00124 throw new SQLException(msg); 00125 } 00126 00127 // Execute Query 00128 try 00129 { 00130 Statement s = c.createStatement(); 00131 if (backend.getDriverCompliance().supportSetQueryTimeout()) 00132 s.setQueryTimeout(request.getTimeout()); 00133 00134 String sql = request.getSQL(); 00135 // Rewrite the query if needed 00136 sql = backend.rewriteQuery(sql); 00137 int rows = s.executeUpdate(sql, 00138 java.sql.Statement.RETURN_GENERATED_KEYS); 00139 if (backendThread.getLogger().isDebugEnabled()) 00140 backendThread.getLogger().debug( 00141 "Request " + request.getId() + " affected " + rows + " rows."); 00142 result = s.getGeneratedKeys(); 00143 00144 // Update schema 00145 if (request.isCreate()) 00146 { // Add the table to the schema 00147 DatabaseSchema dbs = backend.getDatabaseSchema(); 00148 if (dbs != null) 00149 { 00150 DatabaseTable t = ((CreateRequest) request).getDatabaseTable(); 00151 if (t != null) 00152 { 00153 dbs.addTable(t); 00154 if (backendThread.getLogger().isDebugEnabled()) 00155 backendThread.getLogger().debug( 00156 "Added table '" + request.getTableName() 00157 + "' to backend database schema"); 00158 } 00159 } 00160 } 00161 else if (request.isDrop()) 00162 { // Delete the table from the schema 00163 DatabaseSchema dbs = backend.getDatabaseSchema(); 00164 if (dbs != null) 00165 { 00166 DatabaseTable t = dbs.getTable(request.getTableName()); 00167 if (t != null) 00168 { 00169 dbs.removeTable(t); 00170 if (backendThread.getLogger().isDebugEnabled()) 00171 backendThread.getLogger().debug( 00172 "Removed table '" + request.getTableName() 00173 + "' from backend database schema"); 00174 } 00175 } 00176 } 00177 } 00178 catch (SQLException e) 00179 { 00180 try 00181 { // All backends failed, just ignore 00182 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00183 e)) 00184 return; 00185 } 00186 catch (SQLException ignore) 00187 { 00188 } 00189 // Disable this backend (it is no more in sync) by killing the backend 00190 // thread 00191 backendThread.kill(); 00192 String msg = "Request '" 00193 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00194 + "' failed on backend " + backend.getName() + " but " 00195 + getSuccess() + " succeeded (" + e + ")"; 00196 backendThread.getLogger().error(msg); 00197 throw new SQLException(msg); 00198 } 00199 finally 00200 { 00201 cm.releaseConnection(c); 00202 } 00203 } 00204 else 00205 { // Re-use the connection used by this transaction 00206 Connection c; 00207 long tid = request.getTransactionId(); 00208 Long lTid = new Long(tid); 00209 00210 if (!backend.isStartedTransaction(lTid)) 00211 { // Transaction has not been started yet, this is a lazy begin 00212 try 00213 { 00214 c = cm.getConnection(tid); 00215 } 00216 catch (UnreachableBackendException e1) 00217 { 00218 backendThread.getLogger().error( 00219 "Disabling backend " + backend.getName() 00220 + " because it is no more reachable."); 00221 backend.disable(); 00222 throw new SQLException("Backend " + backend.getName() 00223 + " is no more reachable."); 00224 } 00225 00226 // Sanity check 00227 if (c == null) 00228 { // Bad connection 00229 SQLException se = new SQLException( 00230 "Unable to get connection for transaction " + tid); 00231 try 00232 { // All backends failed, just ignore 00233 if (!notifyFailure(backendThread, 00234 (long) request.getTimeout() * 1000, se)) 00235 return; 00236 } 00237 catch (SQLException ignore) 00238 { 00239 } 00240 // Disable this backend (it is no more in sync) by killing the 00241 // backend thread 00242 backendThread.kill(); 00243 String msg = "Request '" 00244 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00245 + "' failed on backend " + backend.getName() + " but " 00246 + getSuccess() + " succeeded (" + se + ")"; 00247 backendThread.getLogger().error(msg); 00248 throw new SQLException(msg); 00249 } 00250 00251 // begin transaction 00252 backend.startTransaction(lTid); 00253 c.setAutoCommit(false); 00254 } 00255 else 00256 { // Transaction has already been started, retrieve connection 00257 c = cm.retrieveConnection(tid); 00258 00259 // Sanity check 00260 if (c == null) 00261 { // Bad connection 00262 SQLException se = new SQLException( 00263 "Unable to retrieve connection for transaction " + tid); 00264 try 00265 { // All backends failed, just ignore 00266 if (!notifyFailure(backendThread, 00267 (long) request.getTimeout() * 1000, se)) 00268 return; 00269 } 00270 catch (SQLException ignore) 00271 { 00272 } 00273 // Disable this backend (it is no more in sync) by killing the 00274 // backend thread 00275 backendThread.kill(); 00276 String msg = "Request '" 00277 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00278 + "' failed on backend " + backend.getName() + " but " 00279 + getSuccess() + " succeeded (" + se + ")"; 00280 backendThread.getLogger().error(msg); 00281 throw new SQLException(msg); 00282 } 00283 } 00284 00285 // Execute Query 00286 try 00287 { 00288 Statement s = c.createStatement(); 00289 if (backend.getDriverCompliance().supportSetQueryTimeout()) 00290 s.setQueryTimeout(request.getTimeout()); 00291 00292 String sql = request.getSQL(); 00293 // Rewrite the query if needed 00294 sql = backend.rewriteQuery(sql); 00295 int rows = s.executeUpdate(sql, 00296 java.sql.Statement.RETURN_GENERATED_KEYS); 00297 if (backendThread.getLogger().isDebugEnabled()) 00298 backendThread.getLogger().debug( 00299 "Request " + request.getId() + " affected " + rows + " rows."); 00300 result = s.getGeneratedKeys(); 00301 00302 // Update schema 00303 if (request.isCreate()) 00304 { // Add the table to the schema 00305 DatabaseSchema dbs = backend.getDatabaseSchema(); 00306 if (dbs != null) 00307 { 00308 DatabaseTable t = ((CreateRequest) request).getDatabaseTable(); 00309 if (t != null) 00310 { 00311 dbs.addTable(t); 00312 if (backendThread.getLogger().isDebugEnabled()) 00313 backendThread.getLogger().debug( 00314 "Added table '" + request.getTableName() 00315 + "' to backend database schema"); 00316 } 00317 } 00318 } 00319 else if (request.isDrop()) 00320 { // Delete the table from the schema 00321 DatabaseSchema dbs = backend.getDatabaseSchema(); 00322 if (dbs != null) 00323 { 00324 DatabaseTable t = dbs.getTable(request.getTableName()); 00325 if (t != null) 00326 { 00327 dbs.removeTable(t); 00328 if (backendThread.getLogger().isDebugEnabled()) 00329 backendThread.getLogger().debug( 00330 "Removed table '" + request.getTableName() 00331 + "' from backend database schema"); 00332 } 00333 } 00334 } 00335 } 00336 catch (SQLException e) 00337 { 00338 try 00339 { // All backends failed, just ignore 00340 if (!notifyFailure(backendThread, (long) request.getTimeout() * 1000, 00341 e)) 00342 return; 00343 } 00344 catch (SQLException ignore) 00345 { 00346 } 00347 // Disable this backend (it is no more in sync) by killing the backend 00348 // thread 00349 backendThread.kill(); 00350 String msg = "Request '" 00351 + request.getSQLShortForm(backend.getSQLShortFormLength()) 00352 + "' failed on backend " + backend.getName() + " but " 00353 + getSuccess() + " succeeded (" + e + ")"; 00354 backendThread.getLogger().error(msg); 00355 throw new SQLException(msg); 00356 } 00357 } 00358 notifySuccess(); 00359 } |
|
Returns the exceptions lists.
AbstractTask.java の 167 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.exceptions.
00168 {
00169 return exceptions;
00170 }
|
|
|
Returns the number of threads that must succeed before returning.
AbstractTask.java の 187 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.nbToComplete.
00188 {
00189 return nbToComplete;
00190 }
|
|
Returns the auto generated keys.
WriteRequestWithKeysTask.java の 366 行で定義されています。
00367 { 00368 return result; 00369 } |
|
|
Returns the total number of threads.
AbstractTask.java の 208 行で定義されています。 参照先 org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.totalNb.
00209 {
00210 return totalNb;
00211 }
|
|
Returns true if this task has a tid attached to it. Used internally by BackendWorkerThread.
AbstractTask.java の 231 行で定義されています。
00232 { 00233 return hasTid; 00234 } |
|
Notifies that the specified backendThread failed to execute this task. If all nodes failed, this method return
AbstractTask.java の 127 行で定義されています。 参照先 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 } |
|
|
Sets the hasTid value. Used internally by BackendWorkerThread.
AbstractTask.java の 243 行で定義されています。 参照元 org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addPriorityTask(), と org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread.addTask().
00244 {
00245 this.hasTid = hasTid;
00246 }
|
|
Sets the total number of threads.
AbstractTask.java の 219 行で定義されています。 参照元 org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2.callStoredProcedure().
00220 {
00221 this.totalNb = totalNb;
00222 }
|
|
WriteRequestWithKeysTask.java の 374 行で定義されています。 参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL().
00375 { 00376 return "WriteTask (" + request.getSQL() + ")"; 00377 } |
|
WriteRequestWithKeysTask.java の 51 行で定義されています。 |
|
WriteRequestWithKeysTask.java の 52 行で定義されています。 |