Public Member Functions | |
BeginTask (int nbToComplete, int totalNb, long timeout, String login, long transactionId) | |
void | executeTask (BackendWorkerThread backendThread) throws SQLException |
String | toString () |
Definition at line 44 of file BeginTask.java.
|
Begins a new transaction given a login and a transaction id.
Definition at line 64 of file BeginTask.java. 00066 { 00067 super(nbToComplete, totalNb); 00068 this.login = login; 00069 this.transactionId = transactionId; 00070 this.timeout = timeout; 00071 }
|
|
Begins a new transaction with the given backend thread.
Implements org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask. Definition at line 79 of file BeginTask.java. References org.objectweb.cjdbc.common.log.Trace.error(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionForTransactionAndLazyBeginIfNeeded(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getConnectionManager(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.getName(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.getSuccess(), org.objectweb.cjdbc.controller.backend.DatabaseBackend.isDisabling(), org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyCompletion(), and org.objectweb.cjdbc.controller.loadbalancer.tasks.AbstractTask.notifyFailure(). 00081 { 00082 DatabaseBackend backend = backendThread.getBackend(); 00083 if (backend.isDisabling()) 00084 { 00085 // Backend is disabling, we do not execute queries except the one in the 00086 // transaction we already started. Just notify the completion for the 00087 // others. 00088 notifyCompletion(); 00089 return; 00090 } 00091 00092 try 00093 { 00094 AbstractConnectionManager cm = backend.getConnectionManager(login); 00095 if (cm == null) 00096 { 00097 SQLException se = new SQLException( 00098 "No Connection Manager for Virtual Login:" + login); 00099 try 00100 { 00101 notifyFailure(backendThread, 1, se); 00102 } 00103 catch (SQLException ignore) 00104 { 00105 00106 } 00107 throw se; 00108 } 00109 00110 Connection c; 00111 Long lTid = new Long(transactionId); 00112 Trace logger = backendThread.getLogger(); 00113 00114 try 00115 { 00116 c = backend.getConnectionForTransactionAndLazyBeginIfNeeded(lTid, cm); 00117 } 00118 catch (UnreachableBackendException ube) 00119 { 00120 SQLException se = new SQLException("Backend " + backend.getName() 00121 + " is no more reachable."); 00122 try 00123 { 00124 notifyFailure(backendThread, 1, se); 00125 } 00126 catch (SQLException ignore) 00127 { 00128 } 00129 // Disable this backend (it is no more in sync) by killing the backend 00130 // thread 00131 backendThread.kill(); 00132 logger.error("Disabling backend " + backend.getName() 00133 + " because it is no more reachable."); 00134 throw se; 00135 } 00136 catch (NoTransactionStartWhenDisablingException e) 00137 { 00138 // Backend is disabling, we do not execute queries except the one in the 00139 // transaction we already started. Just notify the completion for the 00140 // others. 00141 notifyCompletion(); 00142 return; 00143 } 00144 catch (SQLException e1) 00145 { 00146 SQLException se = new SQLException( 00147 "Unable to get connection for transaction " + lTid); 00148 try 00149 { // All backends failed, just ignore 00150 if (!notifyFailure(backendThread, timeout * 1000, se)) 00151 return; 00152 } 00153 catch (SQLException ignore) 00154 { 00155 } 00156 // Disable this backend (it is no more in sync) by killing the 00157 // backend thread 00158 backendThread.kill(); 00159 String msg = "Begin of transaction " + transactionId 00160 + " failed on backend " + backend.getName() + " but " 00161 + getSuccess() + " succeeded (" + se + ")"; 00162 logger.error(msg); 00163 throw new SQLException(msg); 00164 } 00165 00166 // Sanity check 00167 if (c == null) 00168 { // Bad connection 00169 SQLException se = new SQLException( 00170 "No more connection to start a new transaction."); 00171 try 00172 { // All backends failed, just ignore 00173 if (!notifyFailure(backendThread, timeout, se)) 00174 return; 00175 } 00176 catch (SQLException ignore) 00177 { 00178 } 00179 } 00180 else 00181 { 00182 notifyCompletion(); 00183 } 00184 } 00185 catch (Exception e) 00186 { 00187 try 00188 { 00189 if (!notifyFailure(backendThread, timeout, new SQLException(e 00190 .getMessage()))) 00191 return; 00192 } 00193 catch (SQLException ignore) 00194 { 00195 } 00196 String msg = "Failed to begin transaction " + transactionId 00197 + " on backend " + backend.getName() + " (" + e + ")"; 00198 backendThread.getLogger().error(msg); 00199 throw new SQLException(msg); 00200 } 00201 }
|
|
Definition at line 206 of file BeginTask.java. 00207 { 00208 return "BeginTask (" + transactionId + ")"; 00209 }
|