00001
00025
package org.objectweb.cjdbc.controller.loadbalancer.tasks;
00026
00027
import java.sql.Connection;
00028
import java.sql.SQLException;
00029
00030
import org.objectweb.cjdbc.controller.backend.DatabaseBackend;
00031
import org.objectweb.cjdbc.controller.connection.AbstractConnectionManager;
00032
import org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread;
00033
00041 public class RollbackTask extends AbstractTask
00042 {
00044 private String
login;
00045
00047 private long transactionId;
00048
00050 private long timeout;
00051
00061 public RollbackTask(
int nbToComplete,
int totalNb,
long timeout,
00062 String login,
long transactionId)
00063 {
00064 super(nbToComplete, totalNb);
00065
this.login = login;
00066
this.transactionId = transactionId;
00067
this.timeout = timeout;
00068 }
00069
00076 public void execute(
BackendWorkerThread backendThread)
throws SQLException
00077 {
00078
DatabaseBackend db = backendThread.getBackend();
00079 Long lTid =
new Long(
transactionId);
00080
00081
AbstractConnectionManager cm = db.
getConnectionManager(
login);
00082
if (cm == null)
00083 {
00084 SQLException se =
new SQLException(
00085
"No Connection Manager for Virtual Login:" +
login);
00086
try
00087 {
00088
notifyFailure(backendThread, 1, se);
00089 }
00090
catch (SQLException ignore)
00091 {
00092
00093 }
00094
throw se;
00095 }
00096
00097 Connection c = cm.
retrieveConnection(
transactionId);
00098
00099
00100
if (c == null)
00101 {
00102 db.
stopTransaction(lTid);
00103 SQLException se =
new SQLException(
00104
"Unable to retrieve connection for transaction " +
transactionId);
00105
try
00106 {
00107
if (!
notifyFailure(backendThread,
timeout, se))
00108
return;
00109 }
00110
catch (SQLException ignore)
00111 {
00112 }
00113
00114
00115 backendThread.kill();
00116 String msg =
"Failed to rollback transaction " +
transactionId
00117 +
" on backend " + db.
getName() +
" but " +
getSuccess()
00118 +
" succeeded (" + se +
")";
00119 backendThread.getLogger().error(msg);
00120
throw new SQLException(msg);
00121 }
00122
00123
00124
try
00125 {
00126 c.rollback();
00127 c.setAutoCommit(
true);
00128 }
00129
catch (Exception e)
00130 {
00131
try
00132 {
00133
if (!
notifyFailure(backendThread,
timeout,
new SQLException(e
00134 .getMessage())))
00135
return;
00136 }
00137
catch (SQLException ignore)
00138 {
00139 }
00140
00141
00142 backendThread.kill();
00143 String msg =
"Failed to rollback transaction " +
transactionId
00144 +
" on backend " + db.
getName() +
" but " +
getSuccess()
00145 +
" succeeded (" + e +
")";
00146 backendThread.getLogger().error(msg);
00147
throw new SQLException(msg);
00148 }
00149 finally
00150 {
00151 cm.
releaseConnection(
transactionId);
00152 db.
stopTransaction(lTid);
00153 }
00154
notifySuccess();
00155 }
00156
00160 public String
toString()
00161 {
00162
return "RollbackTask (" +
transactionId +
")";
00163 }
00164 }