org.apache.geronimo.concurrent.handlers
abstract public class: TransactionContextHandler [javadoc |
source]
java.lang.Object
org.apache.geronimo.concurrent.handlers.TransactionContextHandler
All Implemented Interfaces:
ManagedContextHandler
Direct Known Subclasses:
TransactionContextHandler
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Field Summary |
---|
protected static final Log | LOG | |
protected static final String | TRANSACTION_MANAGER | |
protected static final String | CLIENT_TRANSACTION | |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.geronimo.concurrent.handlers.TransactionContextHandler Detail: |
protected TransactionManager getTransactionManager(Map<String, Object> threadContext) {
return (TransactionManager)threadContext.get(TRANSACTION_MANAGER);
}
|
public void resumeTransaction(Map<String, Object> threadContext) {
LOG.debug("resumeTransaction");
TransactionManager manager = getTransactionManager(threadContext);
try {
/*
* The Container must detect the case in which a transaction was started, but
* not completed, in the business method, and handle it as follows:
*/
Transaction transaction = manager.getTransaction();
if (transaction == null) {
return;
}
if (transaction.getStatus() != Status.STATUS_ROLLEDBACK &&
transaction.getStatus() != Status.STATUS_COMMITTED) {
String message = "The task started a transaction but did not complete it.";
LOG.error(message);
try {
manager.rollback();
} catch (Throwable t) {
// ignore
}
}
} catch (SystemException e) {
LOG.warn("Error handling transaction", e);
} finally {
Transaction clientTransaction =
(Transaction)threadContext.get(CLIENT_TRANSACTION);
if (clientTransaction != null) {
try {
manager.resume(clientTransaction);
} catch (Exception e) {
LOG.warn("Failed to resume transaction", e);
}
}
}
}
|
public void setContext(Map<String, Object> threadContext) {
LOG.debug("setContext");
if (!isUseParentTransaction(threadContext)) {
suspendTransaction(threadContext);
}
}
|
protected void suspendTransaction(Map<String, Object> threadContext) {
LOG.debug("suspendTransaction");
TransactionManager manager = getTransactionManager(threadContext);
try {
Transaction clientTransaction = manager.suspend();
if (clientTransaction != null) {
threadContext.put(CLIENT_TRANSACTION, clientTransaction);
}
} catch (SystemException e) {
LOG.warn("Failed to suspend transaction", e);
}
}
|
public void unsetContext(Map<String, Object> threadContext) {
LOG.debug("unsetContext");
if (!isUseParentTransaction(threadContext)) {
resumeTransaction(threadContext);
}
}
|