提交 b4cf0bc0 编写于 作者: C cherrylzhao

move SingleXAResource to SPI for other transaction manager integration.

上级 3b1f21a2
......@@ -17,13 +17,12 @@
package io.shardingsphere.transaction.xa.jta.connection;
import io.shardingsphere.transaction.xa.jta.resource.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import lombok.RequiredArgsConstructor;
import javax.sql.ConnectionEventListener;
import javax.sql.StatementEventListener;
import javax.sql.XAConnection;
import javax.transaction.xa.XAResource;
import java.sql.Connection;
import java.sql.SQLException;
......@@ -40,7 +39,7 @@ public final class SingleXAConnection implements XAConnection {
private final XAConnection delegate;
@Override
public XAResource getXAResource() throws SQLException {
public SingleXAResource getXAResource() throws SQLException {
return new SingleXAResource(resourceName, delegate.getXAResource());
}
......
......@@ -20,12 +20,12 @@ package io.shardingsphere.transaction.xa.manager.atomikos;
import com.atomikos.icatch.config.UserTransactionService;
import com.atomikos.icatch.config.UserTransactionServiceImp;
import com.atomikos.icatch.jta.UserTransactionManager;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.XATransactionManager;
import lombok.SneakyThrows;
import javax.sql.XADataSource;
import javax.transaction.Status;
import javax.transaction.xa.XAResource;
/**
* Atomikos XA transaction manager.
......@@ -55,7 +55,7 @@ public final class AtomikosTransactionManager implements XATransactionManager {
@Override
@SneakyThrows
public void enlistResource(final XAResource xaResource) {
public void enlistResource(final SingleXAResource xaResource) {
underlyingTransactionManager.getTransaction().enlistResource(xaResource);
}
......
......@@ -18,7 +18,7 @@
package io.shardingsphere.transaction.xa.manager.atomikos;
import com.atomikos.datasource.xa.jdbc.JdbcTransactionalResource;
import io.shardingsphere.transaction.xa.jta.resource.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import javax.sql.XADataSource;
import javax.transaction.xa.XAResource;
......
......@@ -25,6 +25,7 @@ import io.shardingsphere.transaction.api.TransactionType;
import io.shardingsphere.transaction.xa.fixture.DataSourceUtils;
import io.shardingsphere.transaction.xa.jta.connection.SingleXAConnection;
import io.shardingsphere.transaction.xa.jta.datasource.SingleXADataSource;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.XATransactionManager;
import lombok.SneakyThrows;
import org.junit.Before;
......@@ -36,7 +37,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import javax.sql.XADataSource;
import javax.transaction.Status;
import javax.transaction.xa.XAResource;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.util.HashMap;
......@@ -120,7 +120,7 @@ public class XAShardingTransactionEngineTest {
setCachedSingleXADataSourceMap("ds1");
Connection actual = xaShardingTransactionEngine.getConnection("ds1");
assertThat(actual, instanceOf(Connection.class));
verify(xaTransactionManager).enlistResource(any(XAResource.class));
verify(xaTransactionManager).enlistResource(any(SingleXAResource.class));
}
@Test
......@@ -152,10 +152,10 @@ public class XAShardingTransactionEngineTest {
SingleXADataSource singleXADataSource = mock(SingleXADataSource.class);
SingleXAConnection singleXAConnection = mock(SingleXAConnection.class);
XADataSource xaDataSource = mock(XADataSource.class);
XAResource xaResource = mock(XAResource.class);
SingleXAResource singleXAResource = mock(SingleXAResource.class);
Connection connection = mock(Connection.class);
when(singleXAConnection.getConnection()).thenReturn(connection);
when(singleXAConnection.getXAResource()).thenReturn(xaResource);
when(singleXAConnection.getXAResource()).thenReturn(singleXAResource);
when(singleXADataSource.getXAConnection()).thenReturn(singleXAConnection);
when(singleXADataSource.getResourceName()).thenReturn(datasourceName);
when(singleXADataSource.getXaDataSource()).thenReturn(xaDataSource);
......
......@@ -31,15 +31,13 @@ import io.shardingsphere.transaction.xa.jta.datasource.properties.dialect.SQLSer
import io.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourcePropertyProviderLoaderTest;
import io.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourceSwapperTest;
import io.shardingsphere.transaction.xa.jta.datasource.swapper.impl.DefaultDataSourcePropertyProviderTest;
import io.shardingsphere.transaction.xa.jta.resource.SingleXAResourceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
SingleXAResourceTest.class,
XAPropertiesFactoryTest.class,
XAPropertiesFactoryTest.class,
SingleXADataSourceTest.class,
XADataSourceFactoryTest.class,
DataSourcePropertyProviderLoaderTest.class,
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.xa.jta.connection;
import io.shardingsphere.transaction.xa.jta.resource.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import lombok.SneakyThrows;
import org.junit.Before;
import org.junit.Test;
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.xa.manager.atomikos;
import io.shardingsphere.transaction.xa.jta.resource.SingleXAResource;
import io.shardingsphere.transaction.xa.spi.SingleXAResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......
......@@ -20,7 +20,6 @@ package io.shardingsphere.transaction.xa.spi;
import io.shardingsphere.transaction.core.ShardingTransactionManager;
import javax.sql.XADataSource;
import javax.transaction.xa.XAResource;
/**
* XA transaction manager.
......@@ -52,9 +51,9 @@ public interface XATransactionManager extends ShardingTransactionManager, AutoCl
void removeRecoveryResource(String dataSourceName, XADataSource xaDataSource);
/**
* Enlist resource.
* Enlist single XA resource.
*
* @param xaResource XA resource
* @param singleXAResource single XA resource
*/
void enlistResource(XAResource xaResource);
void enlistResource(SingleXAResource singleXAResource);
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.transaction.xa.spi;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses(
SingleXAResourceTest.class
)
public final class AllTests {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册