jmstransaction.java
来自「提供ESB 应用mule源代码 提供ESB 应用mule源代码」· Java 代码 · 共 97 行
JAVA
97 行
/* * $Id: JmsTransaction.java 12189 2008-06-27 14:57:32Z dfeist $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */package org.mule.transport.jms;import org.mule.api.transaction.TransactionException;import org.mule.config.i18n.CoreMessages;import org.mule.transaction.AbstractSingleResourceTransaction;import org.mule.transaction.IllegalTransactionStateException;import org.mule.transport.jms.i18n.JmsMessages;import javax.jms.Connection;import javax.jms.JMSException;import javax.jms.Session;/** * <code>JmsTransaction</code> is a wrapper for a JMS local transaction. This * object holds the JMS session and controls when the transaction is committed or * rolled back. */public class JmsTransaction extends AbstractSingleResourceTransaction{ public void bindResource(Object key, Object resource) throws TransactionException { if (!(key instanceof Connection) || !(resource instanceof Session)) { throw new IllegalTransactionStateException( CoreMessages.transactionCanOnlyBindToResources("javax.jms.Connection/javax.jms.Session")); } Session session = (Session)resource; try { if (!session.getTransacted()) { throw new IllegalTransactionStateException(JmsMessages.sessionShouldBeTransacted()); } } catch (JMSException e) { throw new IllegalTransactionStateException(CoreMessages.transactionCannotReadState(), e); } super.bindResource(key, resource); } protected void doBegin() throws TransactionException { // do nothing } protected void doCommit() throws TransactionException { if (resource == null) { logger.warn(CoreMessages.noBindingResource()); return; } try { ((Session)resource).commit(); } catch (JMSException e) { throw new TransactionException(CoreMessages.transactionCommitFailed(), e); } } protected void doRollback() throws TransactionException { if (resource == null) { logger.warn(CoreMessages.noBindingResource()); return; } try { ((Session)resource).rollback(); } catch (JMSException e) { throw new TransactionException(CoreMessages.transactionRollbackFailed(), e); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?