use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithoutParameter.
@Test
public void assertParseWithoutParameter() {
ShardingRule shardingRule = createShardingRule();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`, `field2`) VALUES (10, 1)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithoutParameter(insertStatement);
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithParameter.
@Test
public void assertParseWithParameter() {
ShardingRule shardingRule = createShardingRule();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO TABLE_XXX (field1, field2) VALUES (?, ?)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithParameter(insertStatement);
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertParseWithGenerateKeyColumnsWithParameter.
@Test
public void assertParseWithGenerateKeyColumnsWithParameter() {
ShardingRule shardingRule = createShardingRuleWithGenerateKeyColumns();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "INSERT INTO `TABLE_XXX` (`field1`) VALUES (?)", shardingRule);
InsertStatement insertStatement = (InsertStatement) statementParser.parse();
assertInsertStatementWithParameter(insertStatement);
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method createShardingRuleWithGenerateKeyColumns.
private ShardingRule createShardingRuleWithGenerateKeyColumns() {
DataSource dataSource = mock(DataSource.class);
Connection connection = mock(Connection.class);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
try {
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
} catch (final SQLException ex) {
throw new RuntimeException(ex);
}
final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("TABLE_XXX");
tableRuleConfig.setActualDataNodes("ds.table_${0..2}");
tableRuleConfig.setTableShardingStrategyConfig(new ComplexShardingStrategyConfiguration("field1", new TestComplexKeysShardingAlgorithm()));
tableRuleConfig.setKeyGeneratorColumnName("field2");
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
shardingRuleConfig.setDefaultKeyGenerator(new IncrementKeyGenerator());
return new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds"));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingNamespaceTest method assertShardingRuleWithAttributesDataSource.
@Test
public void assertShardingRuleWithAttributesDataSource() {
Map<String, DataSource> dataSourceMap = getDataSourceMap("shardingRuleWithAttributesDataSource");
assertNotNull(dataSourceMap.get("dbtbl_0"));
assertNotNull(dataSourceMap.get("dbtbl_1"));
ShardingRule shardingRule = getShardingRule("shardingRuleWithAttributesDataSource");
assertThat(shardingRule.getDefaultDataSourceName(), is("dbtbl_0"));
assertTrue(Arrays.equals(shardingRule.getDefaultDatabaseShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("standardStrategy", StandardShardingStrategyConfiguration.class).getShardingColumn() }));
assertTrue(Arrays.equals(shardingRule.getDefaultTableShardingStrategy().getShardingColumns().toArray(new String[] {}), new String[] { this.applicationContext.getBean("inlineStrategy", InlineShardingStrategyConfiguration.class).getShardingColumn() }));
assertThat(shardingRule.getDefaultKeyGenerator().getClass().getName(), is("io.shardingjdbc.spring.fixture.IncrementKeyGenerator"));
}
Aggregations