提交 d8114be4 编写于 作者: C cherrylzhao

Move sharding.core => sharding.transaction.spi

上级 1d81839e
......@@ -21,7 +21,6 @@ import io.shardingsphere.spi.NewInstanceServiceLoader;
import io.shardingsphere.spi.executor.SQLExecutionHook;
import io.shardingsphere.spi.parsing.ParsingHook;
import io.shardingsphere.spi.root.RootInvokeHook;
import io.shardingsphere.spi.transaction.ShardingTransactionHandlerRegistry;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
......@@ -38,7 +37,6 @@ public final class ShardingBootstrap {
* Initialize sharding bootstrap.
*/
public static void init() {
ShardingTransactionHandlerRegistry.load();
registerHookClasses(SQLExecutionHook.class, ParsingHook.class, RootInvokeHook.class);
}
......
......@@ -18,45 +18,15 @@
package io.shardingsphere.spi;
import io.shardingsphere.spi.parsing.ParsingHook;
import io.shardingsphere.spi.transaction.xa.DataSourceMapConverter;
import lombok.SneakyThrows;
import org.junit.Test;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class NewInstanceServiceLoaderTest {
@Test
public void assertLoadService() {
Collection<DataSourceMapConverter> collections = NewInstanceServiceLoader.load(DataSourceMapConverter.class);
assertThat(collections.size(), is(1));
assertThat(collections.iterator().next(), instanceOf(DataSourceMapConverter.class));
}
@Test
@SneakyThrows
@SuppressWarnings("unchecked")
public void assertRegisterService() {
NewInstanceServiceLoader.register(DataSourceMapConverter.class);
Field field = NewInstanceServiceLoader.class.getDeclaredField("SERVICE_MAP");
field.setAccessible(true);
Map<Class, Collection<Class<?>>> map = (Map<Class, Collection<Class<?>>>) field.get(null);
assertThat(map.get(DataSourceMapConverter.class).size(), is(1));
}
@Test
public void assertNewServiceInstance() {
NewInstanceServiceLoader.register(DataSourceMapConverter.class);
Collection<DataSourceMapConverter> instances = NewInstanceServiceLoader.newServiceInstances(DataSourceMapConverter.class);
assertThat(instances.size(), is(1));
}
@Test
public void assertNewServiceInstanceNotExist() {
NewInstanceServiceLoader.register(ParsingHook.class);
......
/*
* 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.spi.transaction.xa;
import com.zaxxer.hikari.HikariDataSource;
import io.shardingsphere.core.constant.DatabaseType;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public final class FixedDataSourceMapConverter implements DataSourceMapConverter {
@Override
public Map<String, DataSource> convert(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType) {
Map<String, DataSource> result = new HashMap<>(dataSourceMap.size(), 1);
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
dataSource.setDriverClassName(org.h2.Driver.class.getName());
dataSource.setUsername("sa");
result.put(entry.getKey(), dataSource);
}
return result;
}
}
......@@ -17,6 +17,11 @@
<artifactId>sharding-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-transaction-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-sql-test</artifactId>
......
......@@ -23,9 +23,9 @@ import com.google.common.collect.Multimap;
import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.core.event.transaction.base.SagaTransactionContext;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.context.SagaTransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
import io.shardingsphere.core.transaction.TransactionTypeHolder;
......@@ -34,8 +34,8 @@ import io.shardingsphere.shardingjdbc.jdbc.adapter.executor.ForceExecuteTemplate
import io.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationConnection;
import io.shardingsphere.spi.root.RootInvokeHook;
import io.shardingsphere.spi.root.SPIRootInvokeHook;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.spi.transaction.ShardingTransactionHandlerRegistry;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import io.shardingsphere.shardingjdbc.jdbc.transaction.ShardingTransactionHandlerRegistry;
import lombok.Getter;
import javax.sql.DataSource;
......
......@@ -22,8 +22,8 @@ import io.shardingsphere.core.bootstrap.ShardingBootstrap;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.util.ReflectiveUtil;
import io.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
import io.shardingsphere.spi.transaction.xa.DataSourceMapConverter;
import io.shardingsphere.spi.transaction.xa.SPIDataSourceMapConverter;
import io.shardingsphere.transaction.spi.DataSourceMapConverter;
import io.shardingsphere.shardingjdbc.jdbc.transaction.SPIDataSourceMapConverter;
import lombok.Getter;
import lombok.Setter;
......
......@@ -15,10 +15,11 @@
* </p>
*/
package io.shardingsphere.spi.transaction.xa;
package io.shardingsphere.shardingjdbc.jdbc.transaction;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.spi.NewInstanceServiceLoader;
import io.shardingsphere.transaction.spi.DataSourceMapConverter;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
......
......@@ -15,10 +15,11 @@
* </p>
*/
package io.shardingsphere.spi.transaction;
package io.shardingsphere.shardingjdbc.jdbc.transaction;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -40,20 +41,15 @@ public final class ShardingTransactionHandlerRegistry {
private static final ShardingTransactionHandlerRegistry INSTANCE = new ShardingTransactionHandlerRegistry();
/**
* Get instance of sharding transaction handler registry.
*
* @return sharding transaction handler registry
*/
public static ShardingTransactionHandlerRegistry getInstance() {
return INSTANCE;
static {
load();
}
/**
* Load sharding transaction handler.
*/
@SuppressWarnings("unchecked")
public static void load() {
private static void load() {
for (ShardingTransactionHandler each : ServiceLoader.load(ShardingTransactionHandler.class)) {
if (TRANSACTION_HANDLER_MAP.containsKey(each.getTransactionType())) {
log.warn("Find more than one {} transaction handler implementation class, use `{}` now",
......@@ -64,6 +60,15 @@ public final class ShardingTransactionHandlerRegistry {
}
}
/**
* Get instance of sharding transaction handler registry.
*
* @return sharding transaction handler registry
*/
public static ShardingTransactionHandlerRegistry getInstance() {
return INSTANCE;
}
/**
* Get transaction handler by type.
*
......
......@@ -23,7 +23,7 @@ import io.shardingsphere.api.config.rule.ShardingRuleConfiguration;
import io.shardingsphere.api.config.rule.TableRuleConfiguration;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.core.transaction.TransactionTypeHolder;
import io.shardingsphere.shardingjdbc.fixture.TestDataSource;
import io.shardingsphere.shardingjdbc.jdbc.core.ShardingContext;
......
......@@ -18,8 +18,8 @@
package io.shardingsphere.shardingjdbc.jdbc.core.datasource;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import java.util.HashMap;
import java.util.Map;
......
......@@ -19,7 +19,7 @@ package io.shardingsphere.shardingjdbc.jdbc.core.datasource;
import com.zaxxer.hikari.HikariDataSource;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.spi.transaction.xa.DataSourceMapConverter;
import io.shardingsphere.transaction.spi.DataSourceMapConverter;
import javax.sql.DataSource;
import java.util.HashMap;
......
......@@ -18,8 +18,8 @@
package io.shardingsphere.shardingjdbc.jdbc.core.datasource;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import java.util.HashMap;
import java.util.Map;
......
......@@ -15,7 +15,7 @@
* </p>
*/
package io.shardingsphere.spi.transaction.xa;
package io.shardingsphere.shardingjdbc.jdbc.transaction;
import io.shardingsphere.core.constant.DatabaseType;
import org.junit.Test;
......
......@@ -20,10 +20,9 @@ package io.shardingsphere.shardingproxy.backend.jdbc.connection;
import com.google.common.base.Preconditions;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.spi.transaction.ShardingTransactionHandlerRegistry;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import lombok.RequiredArgsConstructor;
import java.sql.SQLException;
......
......@@ -20,7 +20,7 @@ package io.shardingsphere.shardingproxy.transport.mysql.packet.command.query.tex
import com.google.common.base.Optional;
import io.shardingsphere.core.constant.ShardingConstant;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.shardingproxy.backend.BackendHandler;
import io.shardingsphere.shardingproxy.backend.ResultPacket;
import io.shardingsphere.shardingproxy.backend.jdbc.connection.BackendConnection;
......
......@@ -18,8 +18,8 @@
package io.shardingsphere.shardingproxy.transport.mysql.packet.command.query.text.query;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import java.util.HashMap;
import java.util.Map;
......
......@@ -15,10 +15,10 @@
* </p>
*/
package io.shardingsphere.spi.transaction;
package io.shardingsphere.transaction;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
/**
* Sharding transaction handler SPI.
......
......@@ -15,10 +15,10 @@
* </p>
*/
package io.shardingsphere.core.event.transaction.local;
package io.shardingsphere.transaction.context;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
......
......@@ -15,10 +15,10 @@
* </p>
*/
package io.shardingsphere.core.event.transaction.base;
package io.shardingsphere.transaction.context;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import lombok.Getter;
import lombok.Setter;
......
......@@ -15,7 +15,7 @@
* </p>
*/
package io.shardingsphere.core.event.transaction;
package io.shardingsphere.transaction.context;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
......
......@@ -15,10 +15,10 @@
* </p>
*/
package io.shardingsphere.core.event.transaction.xa;
package io.shardingsphere.transaction.context;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.spi;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
/**
* BASE transaction manager.
......
......@@ -15,7 +15,7 @@
* </p>
*/
package io.shardingsphere.spi.transaction.xa;
package io.shardingsphere.transaction.spi;
import io.shardingsphere.core.constant.DatabaseType;
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.spi;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.core.exception.ShardingException;
/**
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.spi;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.core.rule.DataSourceParameter;
import javax.sql.DataSource;
......
......@@ -17,8 +17,8 @@
package io.shardingsphere.transaction.core.handler;
import io.shardingsphere.core.event.transaction.ShardingTransactionContext;
import io.shardingsphere.spi.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.context.ShardingTransactionContext;
import io.shardingsphere.transaction.ShardingTransactionHandler;
import io.shardingsphere.transaction.spi.ShardingTransactionManager;
/**
......
......@@ -19,7 +19,7 @@ package io.shardingsphere.transaction.xa.convert;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.spi.transaction.xa.DataSourceMapConverter;
import io.shardingsphere.transaction.spi.DataSourceMapConverter;
import io.shardingsphere.transaction.spi.XATransactionManager;
import io.shardingsphere.transaction.xa.convert.dialect.XADataSourceFactory;
import io.shardingsphere.transaction.xa.convert.swap.DataSourceSwapperRegistry;
......
......@@ -18,7 +18,7 @@
package io.shardingsphere.transaction.xa.handler;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.transaction.spi.ShardingTransactionManager;
import io.shardingsphere.transaction.core.handler.ShardingTransactionHandlerAdapter;
import io.shardingsphere.transaction.xa.manager.XATransactionManagerSPILoader;
......
......@@ -18,7 +18,7 @@
package io.shardingsphere.transaction.xa.manager;
import com.atomikos.icatch.jta.UserTransactionManager;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.transaction.spi.XATransactionManager;
......
......@@ -17,7 +17,7 @@
package io.shardingsphere.transaction.xa.fixture;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.transaction.spi.XATransactionManager;
......
......@@ -19,7 +19,7 @@ package io.shardingsphere.transaction.xa.handler;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.transaction.spi.ShardingTransactionManager;
import io.shardingsphere.transaction.xa.manager.AtomikosTransactionManager;
import org.junit.Test;
......
......@@ -21,7 +21,7 @@ import com.atomikos.icatch.jta.UserTransactionManager;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.event.transaction.xa.XATransactionContext;
import io.shardingsphere.transaction.context.XATransactionContext;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.transaction.xa.fixture.ReflectiveUtil;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册