use of io.shardingjdbc.core.jdbc.core.ShardingContext in project sharding-jdbc by shardingjdbc.
the class ShardingConnectionTest method setUp.
@Before
public void setUp() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("test");
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
dataSourceMap.put(DS_NAME, masterSlaveDataSource);
ShardingContext shardingContext = new ShardingContext(dataSourceMap, new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()), null, null, false);
connection = new ShardingConnection(shardingContext);
}
use of io.shardingjdbc.core.jdbc.core.ShardingContext in project sharding-jdbc by shardingjdbc.
the class OrchestrationSpringBootShardingTest method assertWithShardingDataSource.
@Test
public void assertWithShardingDataSource() throws NoSuchFieldException, IllegalAccessException {
assertTrue(dataSource instanceof ShardingDataSource);
Field field = ShardingDataSource.class.getDeclaredField("shardingContext");
field.setAccessible(true);
ShardingContext shardingContext = (ShardingContext) field.get(dataSource);
for (DataSource each : shardingContext.getDataSourceMap().values()) {
assertThat(((BasicDataSource) each).getMaxTotal(), is(16));
}
assertTrue(shardingContext.isShowSQL());
Map<String, Object> configMap = new ConcurrentHashMap<>();
configMap.put("key1", "value1");
assertThat(ConfigMapContext.getInstance().getShardingConfig(), is(configMap));
Field propertiesField = ShardingDataSource.class.getDeclaredField("shardingProperties");
propertiesField.setAccessible(true);
ShardingProperties shardingProperties = (ShardingProperties) propertiesField.get(dataSource);
assertTrue((Boolean) shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW));
assertThat((Integer) shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE), is(100));
}
use of io.shardingjdbc.core.jdbc.core.ShardingContext in project sharding-jdbc by shardingjdbc.
the class ShardingDataSourceFactoryTest method getShardingRule.
private ShardingRule getShardingRule(final DataSource dataSource) throws NoSuchFieldException, IllegalAccessException {
Field field = dataSource.getClass().getDeclaredField("shardingContext");
field.setAccessible(true);
return ((ShardingContext) field.get(dataSource)).getShardingRule();
}
use of io.shardingjdbc.core.jdbc.core.ShardingContext in project sharding-jdbc by shardingjdbc.
the class AbstractSQLTest method getDataSourceMap.
private static Map<String, DataSource> getDataSourceMap(final ShardingDataSource shardingDataSource) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Field field = shardingDataSource.getClass().getDeclaredField("shardingContext");
field.setAccessible(true);
ShardingContext shardingContext = (ShardingContext) field.get(shardingDataSource);
return shardingContext.getDataSourceMap();
}
use of io.shardingjdbc.core.jdbc.core.ShardingContext in project sharding-jdbc by shardingjdbc.
the class ShardingDataSource method renew.
/**
* Renew sharding data source.
*
* @param newDataSourceMap new data source map
* @param newShardingRule new sharding rule
* @param newProps new sharding properties
*/
public void renew(final Map<String, DataSource> newDataSourceMap, final ShardingRule newShardingRule, final Properties newProps) {
ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps);
int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE);
if (originalExecutorSize != newExecutorSize) {
ExecutorEngine originalExecutorEngine = executorEngine;
executorEngine = new ExecutorEngine(newExecutorSize);
originalExecutorEngine.close();
}
boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW);
shardingProperties = newShardingProperties;
shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, newShowSQL);
}
Aggregations