Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from WeBankFinTech/dev
v1.2.0
- Loading branch information
Showing
51 changed files
with
591 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/base/BaseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/base/ResponseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/base/exception/BaseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/base/exception/ExceptionsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/com/webank/webase/transaction/config/MyComplexShardingAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2014-2019 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.webank.webase.transaction.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Collection; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import com.alibaba.fastjson.JSON; | ||
import io.shardingsphere.api.algorithm.sharding.ListShardingValue; | ||
import io.shardingsphere.api.algorithm.sharding.ShardingValue; | ||
import io.shardingsphere.api.algorithm.sharding.complex.ComplexKeysShardingAlgorithm; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class MyComplexShardingAlgorithm implements ComplexKeysShardingAlgorithm { | ||
@Override | ||
public Collection<String> doSharding(Collection<String> collection, Collection<ShardingValue> shardingValues) { | ||
log.debug("collection:" + JSON.toJSONString(collection) + ",shardingValues:" + JSON.toJSONString(shardingValues)); | ||
// 根据id和gmt_create双分片键来进行分表 | ||
Collection<Long> idValues = getLongShardingValue(shardingValues, "id"); | ||
Collection<Date> gmtValues = getDateShardingValue(shardingValues, "gmt_create"); | ||
List<String> shardingSuffix = new ArrayList<>(); | ||
for (Long idValue : idValues) { | ||
for (Date gmtValue : gmtValues) { | ||
Calendar cld = Calendar.getInstance(); | ||
cld.setTime(gmtValue); | ||
int year = cld.get(Calendar.YEAR); | ||
String suffix = "_" + year + "_" + idValue % 2; | ||
collection.forEach(x -> { | ||
if (x.endsWith(suffix)) { | ||
shardingSuffix.add(x); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return shardingSuffix; | ||
} | ||
|
||
private Collection<Long> getLongShardingValue(Collection<ShardingValue> shardingValues, final String key) { | ||
Collection<Long> valueSet = new ArrayList<>(); | ||
Iterator<ShardingValue> iterator = shardingValues.iterator(); | ||
while (iterator.hasNext()) { | ||
ShardingValue next = iterator.next(); | ||
if (next instanceof ListShardingValue) { | ||
ListShardingValue value = (ListShardingValue) next; | ||
if (value.getColumnName().equals(key)) { | ||
return value.getValues(); | ||
} | ||
} | ||
} | ||
return valueSet; | ||
} | ||
|
||
private Collection<Date> getDateShardingValue(Collection<ShardingValue> shardingValues, final String key) { | ||
Collection<Date> valueSet = new ArrayList<>(); | ||
Iterator<ShardingValue> iterator = shardingValues.iterator(); | ||
while (iterator.hasNext()) { | ||
ShardingValue next = iterator.next(); | ||
if (next instanceof ListShardingValue) { | ||
ListShardingValue value = (ListShardingValue) next; | ||
if (value.getColumnName().equals(key)) { | ||
return value.getValues(); | ||
} | ||
} | ||
} | ||
return valueSet; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/config/RestTemplateConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/config/ThreadConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/contract/CompileInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/webank/webase/transaction/contract/ContractController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.