001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.transaction.jta;
018
019import javax.transaction.NotSupportedException;
020import javax.transaction.SystemException;
021import javax.transaction.Transaction;
022
023/**
024 * Strategy interface for creating JTA {@link javax.transaction.Transaction}
025 * objects based on specified transactional characteristics.
026 *
027 * <p>The default implementation, {@link SimpleTransactionFactory}, simply
028 * wraps a standard JTA {@link javax.transaction.TransactionManager}.
029 * This strategy interface allows for more sophisticated implementations
030 * that adapt to vendor-specific JTA extensions.
031 *
032 * @author Juergen Hoeller
033 * @since 2.5
034 * @see javax.transaction.TransactionManager#getTransaction()
035 * @see SimpleTransactionFactory
036 * @see JtaTransactionManager
037 */
038public interface TransactionFactory {
039
040        /**
041         * Create an active Transaction object based on the given name and timeout.
042         * @param name the transaction name (may be {@code null})
043         * @param timeout the transaction timeout (may be -1 for the default timeout)
044         * @return the active Transaction object (never {@code null})
045         * @throws NotSupportedException if the transaction manager does not support
046         * a transaction of the specified type
047         * @throws SystemException if the transaction manager failed to create the
048         * transaction
049         */
050        Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException;
051
052        /**
053         * Determine whether the underlying transaction manager supports XA transactions
054         * managed by a resource adapter (i.e. without explicit XA resource enlistment).
055         * <p>Typically {@code false}. Checked by
056         * {@link org.springframework.jca.endpoint.AbstractMessageEndpointFactory}
057         * in order to differentiate between invalid configuration and valid
058         * ResourceAdapter-managed transactions.
059         * @see javax.resource.spi.ResourceAdapter#endpointActivation
060         * @see javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted
061         */
062        boolean supportsResourceAdapterManagedTransactions();
063
064}