Loading sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecutorEngine.java +3 −11 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.event.overall.OverallExecutionEvent; import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler; import lombok.Getter; import lombok.RequiredArgsConstructor; import java.sql.SQLException; import java.util.Collection; Loading @@ -39,18 +40,14 @@ import java.util.Map; * @author maxiaoguang * @author panjuan */ public final class SQLExecutorEngine implements AutoCloseable { @RequiredArgsConstructor public final class SQLExecutorEngine { @Getter private final ShardingExecuteEngine shardingExecuteEngine; private final ConnectionMode connectionMode; public SQLExecutorEngine(final int executorSize, final ConnectionMode connectionMode) { shardingExecuteEngine = new ShardingExecuteEngine(executorSize); this.connectionMode = connectionMode; } /** * Execute. * Loading Loading @@ -90,9 +87,4 @@ public final class SQLExecutorEngine implements AutoCloseable { } return result; } @Override public void close() { shardingExecuteEngine.close(); } } sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +2 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package io.shardingsphere.core.jdbc.core; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.ShardingExecuteEngine; import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; Loading @@ -44,7 +44,7 @@ public final class ShardingContext { private final DatabaseType databaseType; private final SQLExecutorEngine executorEngine; private final ShardingExecuteEngine executeEngine; private final ShardingMetaData metaData; Loading sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +12 −13 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.properties.ShardingProperties; import io.shardingsphere.core.constant.properties.ShardingPropertiesConstant; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.ShardingExecuteEngine; import io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; Loading Loading @@ -56,7 +56,7 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut @Getter private ShardingProperties shardingProperties; private SQLExecutorEngine executorEngine; private ShardingExecuteEngine executeEngine; private ShardingContext shardingContext; Loading @@ -72,11 +72,11 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut shardingProperties = new ShardingProperties(null == props ? new Properties() : props); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); executorEngine = new SQLExecutorEngine(executorSize, connectionMode); executeEngine = new ShardingExecuteEngine(executorSize); ShardingMetaData shardingMetaData = new ShardingMetaData(getDataSourceURLs(dataSourceMap), shardingRule, getDatabaseType(), executorEngine.getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)); executeEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingMetaData, connectionMode, showSQL); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executeEngine, shardingMetaData, connectionMode, showSQL); } private static Map<String, String> getDataSourceURLs(final Map<String, DataSource> dataSourceMap) { Loading Loading @@ -106,18 +106,17 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps); int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode originalConnectionMode = ConnectionMode.valueOf(shardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); ConnectionMode newConnectionMode = ConnectionMode.valueOf(newShardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); if (originalExecutorSize != newExecutorSize || originalConnectionMode != newConnectionMode) { SQLExecutorEngine originalExecutorEngine = executorEngine; executorEngine = new SQLExecutorEngine(newExecutorSize, newConnectionMode); originalExecutorEngine.close(); if (originalExecutorSize != newExecutorSize) { ShardingExecuteEngine originalExecuteEngine = executeEngine; executeEngine = new ShardingExecuteEngine(newExecutorSize); originalExecuteEngine.close(); } shardingProperties = newShardingProperties; ShardingMetaData shardingMetaData = new ShardingMetaData(getDataSourceURLs(newDataSourceMap), newShardingRule, getDatabaseType(), executorEngine.getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)); executeEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)); boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newConnectionMode, newShowSQL); shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executeEngine, shardingMetaData, newConnectionMode, newShowSQL); } @Override Loading @@ -127,7 +126,7 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut @Override public void close() { executorEngine.close(); executeEngine.close(); } protected static Map<String, DataSource> getRawDataSourceMap(final Map<String, DataSource> dataSourceMap) { Loading sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +11 −10 Original line number Diff line number Diff line Loading @@ -23,10 +23,11 @@ import com.google.common.collect.Iterators; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.result.MemoryQueryResult; import io.shardingsphere.core.executor.result.StreamQueryResult; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; import io.shardingsphere.core.executor.type.prepared.PreparedStatementExecutor; import io.shardingsphere.core.executor.type.prepared.PreparedStatementUnit; import io.shardingsphere.core.jdbc.adapter.AbstractShardingPreparedStatementAdapter; Loading Loading @@ -136,8 +137,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta ResultSet result; try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); List<ResultSet> resultSets = new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeQuery(); List<ResultSet> resultSets = new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeQuery(); MergeEngine mergeEngine = MergeEngineFactory.newInstance( connection.getShardingContext().getShardingRule(), getQueryResults(resultSets), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); result = new ShardingResultSet(resultSets, merge(mergeEngine), this); Loading Loading @@ -165,8 +166,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta routedStatements.clear(); try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); return new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeUpdate(); return new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeUpdate(); } finally { refreshTableMetaData(); clearBatch(); Loading @@ -178,8 +179,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta routedStatements.clear(); try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); return new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).execute(); return new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).execute(); } finally { refreshTableMetaData(); clearBatch(); Loading Loading @@ -247,7 +248,7 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getShardingExecuteEngine().getExecutorService(), connection.getShardingContext().getExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } Loading Loading @@ -307,7 +308,7 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta @Override public int[] executeBatch() throws SQLException { try { return new BatchPreparedStatementExecutor(connection.getShardingContext().getExecutorEngine(), return new BatchPreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), connection.getShardingContext().getDatabaseType(), routeResult.getSqlStatement().getType(), batchStatementUnits, batchCount).executeBatch(); } finally { clearBatch(); Loading sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +7 −5 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package io.shardingsphere.core.jdbc.core.statement; import com.google.common.base.Optional; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.result.MemoryQueryResult; import io.shardingsphere.core.executor.result.StreamQueryResult; import io.shardingsphere.core.executor.type.statement.StatementExecutor; Loading @@ -45,7 +47,6 @@ import io.shardingsphere.core.routing.SQLRouteResult; import io.shardingsphere.core.routing.StatementRoutingEngine; import io.shardingsphere.core.routing.event.RoutingEvent; import io.shardingsphere.core.routing.router.sharding.GeneratedKey; import io.shardingsphere.core.event.ShardingEventBusInstance; import lombok.AccessLevel; import lombok.Getter; Loading Loading @@ -222,9 +223,11 @@ public final class ShardingStatement extends AbstractStatementAdapter { clearPrevious(); sqlRoute(sql); if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); return new StatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); } return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); return new StatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); } private Collection<StatementUnit> getStatementUnitsForConnectionStrictly() throws SQLException { Loading Loading @@ -285,8 +288,7 @@ public final class ShardingStatement extends AbstractStatementAdapter { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } Loading Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecutorEngine.java +3 −11 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.event.overall.OverallExecutionEvent; import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler; import lombok.Getter; import lombok.RequiredArgsConstructor; import java.sql.SQLException; import java.util.Collection; Loading @@ -39,18 +40,14 @@ import java.util.Map; * @author maxiaoguang * @author panjuan */ public final class SQLExecutorEngine implements AutoCloseable { @RequiredArgsConstructor public final class SQLExecutorEngine { @Getter private final ShardingExecuteEngine shardingExecuteEngine; private final ConnectionMode connectionMode; public SQLExecutorEngine(final int executorSize, final ConnectionMode connectionMode) { shardingExecuteEngine = new ShardingExecuteEngine(executorSize); this.connectionMode = connectionMode; } /** * Execute. * Loading Loading @@ -90,9 +87,4 @@ public final class SQLExecutorEngine implements AutoCloseable { } return result; } @Override public void close() { shardingExecuteEngine.close(); } }
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +2 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package io.shardingsphere.core.jdbc.core; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.ShardingExecuteEngine; import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; Loading @@ -44,7 +44,7 @@ public final class ShardingContext { private final DatabaseType databaseType; private final SQLExecutorEngine executorEngine; private final ShardingExecuteEngine executeEngine; private final ShardingMetaData metaData; Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +12 −13 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.properties.ShardingProperties; import io.shardingsphere.core.constant.properties.ShardingPropertiesConstant; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.ShardingExecuteEngine; import io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; Loading Loading @@ -56,7 +56,7 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut @Getter private ShardingProperties shardingProperties; private SQLExecutorEngine executorEngine; private ShardingExecuteEngine executeEngine; private ShardingContext shardingContext; Loading @@ -72,11 +72,11 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut shardingProperties = new ShardingProperties(null == props ? new Properties() : props); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); executorEngine = new SQLExecutorEngine(executorSize, connectionMode); executeEngine = new ShardingExecuteEngine(executorSize); ShardingMetaData shardingMetaData = new ShardingMetaData(getDataSourceURLs(dataSourceMap), shardingRule, getDatabaseType(), executorEngine.getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)); executeEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingMetaData, connectionMode, showSQL); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executeEngine, shardingMetaData, connectionMode, showSQL); } private static Map<String, String> getDataSourceURLs(final Map<String, DataSource> dataSourceMap) { Loading Loading @@ -106,18 +106,17 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps); int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode originalConnectionMode = ConnectionMode.valueOf(shardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); ConnectionMode newConnectionMode = ConnectionMode.valueOf(newShardingProperties.<String>getValue(ShardingPropertiesConstant.CONNECTION_MODE)); if (originalExecutorSize != newExecutorSize || originalConnectionMode != newConnectionMode) { SQLExecutorEngine originalExecutorEngine = executorEngine; executorEngine = new SQLExecutorEngine(newExecutorSize, newConnectionMode); originalExecutorEngine.close(); if (originalExecutorSize != newExecutorSize) { ShardingExecuteEngine originalExecuteEngine = executeEngine; executeEngine = new ShardingExecuteEngine(newExecutorSize); originalExecuteEngine.close(); } shardingProperties = newShardingProperties; ShardingMetaData shardingMetaData = new ShardingMetaData(getDataSourceURLs(newDataSourceMap), newShardingRule, getDatabaseType(), executorEngine.getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)); executeEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)); boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newConnectionMode, newShowSQL); shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executeEngine, shardingMetaData, newConnectionMode, newShowSQL); } @Override Loading @@ -127,7 +126,7 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut @Override public void close() { executorEngine.close(); executeEngine.close(); } protected static Map<String, DataSource> getRawDataSourceMap(final Map<String, DataSource> dataSourceMap) { Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +11 −10 Original line number Diff line number Diff line Loading @@ -23,10 +23,11 @@ import com.google.common.collect.Iterators; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.result.MemoryQueryResult; import io.shardingsphere.core.executor.result.StreamQueryResult; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; import io.shardingsphere.core.executor.type.prepared.PreparedStatementExecutor; import io.shardingsphere.core.executor.type.prepared.PreparedStatementUnit; import io.shardingsphere.core.jdbc.adapter.AbstractShardingPreparedStatementAdapter; Loading Loading @@ -136,8 +137,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta ResultSet result; try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); List<ResultSet> resultSets = new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeQuery(); List<ResultSet> resultSets = new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeQuery(); MergeEngine mergeEngine = MergeEngineFactory.newInstance( connection.getShardingContext().getShardingRule(), getQueryResults(resultSets), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); result = new ShardingResultSet(resultSets, merge(mergeEngine), this); Loading Loading @@ -165,8 +166,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta routedStatements.clear(); try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); return new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeUpdate(); return new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeUpdate(); } finally { refreshTableMetaData(); clearBatch(); Loading @@ -178,8 +179,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta routedStatements.clear(); try { Collection<PreparedStatementUnit> preparedStatementUnits = route(); return new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).execute(); return new PreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), preparedStatementUnits).execute(); } finally { refreshTableMetaData(); clearBatch(); Loading Loading @@ -247,7 +248,7 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getShardingExecuteEngine().getExecutorService(), connection.getShardingContext().getExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } Loading Loading @@ -307,7 +308,7 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta @Override public int[] executeBatch() throws SQLException { try { return new BatchPreparedStatementExecutor(connection.getShardingContext().getExecutorEngine(), return new BatchPreparedStatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), connection.getShardingContext().getDatabaseType(), routeResult.getSqlStatement().getType(), batchStatementUnits, batchCount).executeBatch(); } finally { clearBatch(); Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +7 −5 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package io.shardingsphere.core.jdbc.core.statement; import com.google.common.base.Optional; import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.event.ShardingEventBusInstance; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.result.MemoryQueryResult; import io.shardingsphere.core.executor.result.StreamQueryResult; import io.shardingsphere.core.executor.type.statement.StatementExecutor; Loading @@ -45,7 +47,6 @@ import io.shardingsphere.core.routing.SQLRouteResult; import io.shardingsphere.core.routing.StatementRoutingEngine; import io.shardingsphere.core.routing.event.RoutingEvent; import io.shardingsphere.core.routing.router.sharding.GeneratedKey; import io.shardingsphere.core.event.ShardingEventBusInstance; import lombok.AccessLevel; import lombok.Getter; Loading Loading @@ -222,9 +223,11 @@ public final class ShardingStatement extends AbstractStatementAdapter { clearPrevious(); sqlRoute(sql); if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); return new StatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); } return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); return new StatementExecutor(new SQLExecutorEngine(connection.getShardingContext().getExecuteEngine(), connection.getShardingContext().getConnectionMode()), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); } private Collection<StatementUnit> getStatementUnitsForConnectionStrictly() throws SQLException { Loading Loading @@ -285,8 +288,7 @@ public final class ShardingStatement extends AbstractStatementAdapter { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getShardingExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getExecuteEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } Loading