forked from hs-web/hsweb-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加动态切换表 hsweb.datasource.table.static-mapping
- Loading branch information
Showing
4 changed files
with
92 additions
and
14 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
36 changes: 36 additions & 0 deletions
36
...ce-api/src/main/java/org/hswebframework/web/datasource/switcher/DefaultTableSwitcher.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,36 @@ | ||
package org.hswebframework.web.datasource.switcher; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.hswebframework.web.ThreadLocalUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author zhouhao | ||
* @since 3.0.0-RC | ||
*/ | ||
public class DefaultTableSwitcher implements TableSwitcher { | ||
|
||
private Map<String, String> staticMapping = new HashMap<>(); | ||
|
||
@Override | ||
public void use(String source, String target) { | ||
getMapping().put(source, target); | ||
} | ||
|
||
private Map<String, String> getMapping() { | ||
return ThreadLocalUtils.get(DefaultTableSwitcher.class.getName() + "_current", HashMap::new); | ||
} | ||
|
||
@Override | ||
public String getTable(String name) { | ||
return getMapping() | ||
.getOrDefault(name, staticMapping.getOrDefault(name, name)); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
ThreadLocalUtils.remove(DefaultTableSwitcher.class.getName() + "_current"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...atasource-api/src/main/java/org/hswebframework/web/datasource/switcher/TableSwitcher.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,15 @@ | ||
package org.hswebframework.web.datasource.switcher; | ||
|
||
/** | ||
* 表切换器 | ||
* | ||
* @author zhouhao | ||
* @since 3.0.0-RC | ||
*/ | ||
public interface TableSwitcher { | ||
void use(String source, String target); | ||
|
||
String getTable(String name); | ||
|
||
void reset(); | ||
} |