Skip to content

Commit

Permalink
Fixed #525.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed Jan 4, 2018
1 parent a82dee4 commit 8f9e2c2
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 2 deletions.
5 changes: 3 additions & 2 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
## 2.0.2

### 功能提升
1. [ISSUE #475](https://github.com/shardingjdbc/sharding-jdbc/issues/475) 支持create index语句
1. [ISSUE #475](https://github.com/shardingjdbc/sharding-jdbc/issues/475) 支持CREATE INDEX
1. [ISSUE #525](https://github.com/shardingjdbc/sharding-jdbc/issues/525) 支持DROP INDEX

### 缺陷修正
1. [ISSUE #520](https://github.com/shardingjdbc/sharding-jdbc/issues/520) 引入分表后,唯一键冲突时异常类型不再是DuplicateKeyException
1. [ISSUE #521](https://github.com/shardingjdbc/sharding-jdbc/issues/521) YAML文件中ShardingProperties设置无效
1. [ISSUE #522](https://github.com/shardingjdbc/sharding-jdbc/issues/522) 读写分离Slave库不需要执行DDL语句

## 2.0.1

### 功能提升
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ public final class ShardingDataSourceBeanDefinitionParserTag {
public static final String COLUMN_KEY_GENERATOR_CLASS = "column-key-generator-class";

public static final String KEY_GENERATOR_CLASS = "key-generator-class";

public static final String LOGIC_INDEX = "logic-index";
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ private BeanDefinition parseTableRuleConfig(final Element tableElement) {
if (!Strings.isNullOrEmpty(keyGeneratorClass)) {
factory.addPropertyValue("keyGeneratorClass", keyGeneratorClass);
}
String logicIndex = tableElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.LOGIC_INDEX);
if (!Strings.isNullOrEmpty(logicIndex)) {
factory.addPropertyValue("logicIndex", logicIndex);
}
return factory.getBeanDefinition();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<xsd:attribute name="table-strategy-ref" type="xsd:string" use="optional" />
<xsd:attribute name="generate-key-column" type="xsd:string" use="optional" />
<xsd:attribute name="column-key-generator-class" type="xsd:string" use="optional"/>
<xsd:attribute name="logic-index" type="xsd:string" use="optional" />
</xsd:complexType>
</xsd:element>
<xsd:element name="binding-table-rules">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2015 dangdang.com.
* <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.shardingjdbc.spring.cases;

import io.shardingjdbc.spring.AbstractShardingBothDataBasesAndTablesSpringDBUnitTest;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@ContextConfiguration(locations = "classpath:META-INF/rdb/withNamespaceLogicIndex.xml")
public final class WithNamespaceLogicIndexTest extends AbstractShardingBothDataBasesAndTablesSpringDBUnitTest {

@Test
public void assertIndex() throws SQLException {
try (Connection connection = getShardingDataSource().getConnection()) {
String sql = "CREATE INDEX t_order_index ON t_order(user_id)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.execute();
sql = "DROP INDEX t_order_index";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.execute();
preparedStatement.close();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sharding="http://shardingjdbc.io/schema/shardingjdbc/sharding"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://shardingjdbc.io/schema/shardingjdbc/sharding
http://shardingjdbc.io/schema/shardingjdbc/sharding/sharding.xsd
">
<import resource="datasource/dataSource.xml" />

<sharding:standard-strategy id="databaseStrategy" sharding-column="user_id" precise-algorithm-class="io.shardingjdbc.spring.algorithm.PreciseModuloDatabaseShardingAlgorithm" />
<sharding:standard-strategy id="tableStrategy" sharding-column="order_id" precise-algorithm-class="io.shardingjdbc.spring.algorithm.PreciseModuloTableShardingAlgorithm" />

<sharding:data-source id="shardingDatasource">
<sharding:sharding-rule data-source-names="dbtbl_0,dbtbl_1" default-data-source-name="dbtbl_0">
<sharding:table-rules>
<sharding:table-rule logic-table="t_order" actual-data-nodes="dbtbl_${0..1}.t_order_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="tableStrategy" logic-index="t_order_index"/>
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="dbtbl_${0..1}.t_order_item_${0..3}" database-strategy-ref="databaseStrategy" table-strategy-ref="tableStrategy" />
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule logic-tables="t_order, t_order_item" />
</sharding:binding-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ public final class ShardingDataSourceBeanDefinitionParserTag {
public static final String COLUMN_KEY_GENERATOR_CLASS = "column-key-generator-class";

public static final String KEY_GENERATOR_CLASS = "key-generator-class";

public static final String LOGIC_INDEX_ATTRIBUTE = "logic-index";
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private BeanDefinition parseTableRuleConfig(final Element tableElement) {
if (!Strings.isNullOrEmpty(keyGeneratorClass)) {
factory.addPropertyValue("keyGeneratorClass", keyGeneratorClass);
}
String logicIndex = tableElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.LOGIC_INDEX_ATTRIBUTE);
if (!Strings.isNullOrEmpty(logicIndex)) {
factory.addPropertyValue("logicIndex", logicIndex);
}
return factory.getBeanDefinition();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<xsd:attribute name="table-strategy-ref" type="xsd:string" use="optional" />
<xsd:attribute name="generate-key-column" type="xsd:string" use="optional" />
<xsd:attribute name="column-key-generator-class" type="xsd:string" use="optional"/>
<xsd:attribute name="logic-index" type="xsd:string" use="optional" />
</xsd:complexType>
</xsd:element>
<xsd:element name="binding-table-rules">
Expand Down

0 comments on commit 8f9e2c2

Please sign in to comment.