DistributeTableStrategy增加getSource接口,待实现

This commit is contained in:
redkale
2024-01-06 12:19:16 +08:00
parent 87f46d2785
commit 81340be2e1
6 changed files with 93 additions and 7 deletions

View File

@@ -46,7 +46,7 @@ redkale.datasource.platf.password = pwd123
</dependency>
```
&emsp;&emsp; 使用vertx-mysql-client实现, 需要依赖官方扩展包 ```redkale-plugins```
&emsp;&emsp; 异步场景可使用vertx-mysql-client实现, 需要依赖官方扩展包 ```redkale-plugins```
```xml
<dependency>
<groupId>org.redkalex</groupId>

View File

@@ -2951,7 +2951,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
protected <T> CompletableFuture<Boolean> existsDBApply(EntityInfo<T> info, CompletableFuture<? extends DataResultSet> future, boolean onlypk) {
return future.thenApply((DataResultSet pgset) -> {
boolean rs = pgset.next() ? (((Number) pgset.getObject(1)).intValue() > 0) : false;
boolean rs = pgset.next() && (((Number) pgset.getObject(1)).intValue() > 0);
pgset.close();
return rs;
});

View File

@@ -22,6 +22,48 @@ import java.io.Serializable;
*/
public interface DistributeTableStrategy<T> {
/**
* 获取DataSource资源名为null表示没有分布物理库 <br>
* 查询单个对象DataSource.find时调用本方法 <br>
*
* @param primary 记录主键
*
* @return DataSource资源名
*
* @since 2.8.0
*/
default String getSource(Serializable primary) {
return null;
}
/**
* 获取DataSource资源名为null表示没有分布物理库 <br>
* 新增对象或更新单个对象DataSource.insert、DataSource.update时调用本方法 <br>
*
* @param bean 实体对象
*
* @return DataSource资源名
*
* @since 2.8.0
*/
default String getSource(T bean) {
return null;
}
/**
* 获取DataSource资源名为null表示没有分布物理库 <br>
* 查询、修改、删除对象DataSource.find、DataSource.query、DataSource.delete、DataSource.update时调用本方法 <br>
*
* @param node 过滤条件
*
* @return DataSource资源名
*
* @since 2.8.0
*/
default String getSource(FilterNode node) {
return null;
}
/**
* 获取对象的表名 <br>
* 查询单个对象DataSource.find时调用本方法获取表名 <br>

View File

@@ -1195,6 +1195,48 @@ public final class EntityInfo<T> {
return map;
}
/**
* 获取DataSource资源名为null表示没有分布物理库
*
* @param primary Entity主键值
*
* @return String
*/
public String getSource(Serializable primary) {
if (tableStrategy == null) {
return null;
}
return tableStrategy.getSource(primary);
}
/**
* 获取DataSource资源名为null表示没有分布物理库
*
* @param bean Entity实体
*
* @return String
*/
public String getSource(T bean) {
if (tableStrategy == null) {
return null;
}
return tableStrategy.getSource(bean);
}
/**
* 获取DataSource资源名为null表示没有分布物理库
*
* @param node FilterNode
*
* @return String
*/
public String getSource(FilterNode node) {
if (tableStrategy == null) {
return null;
}
return tableStrategy.getSource(node);
}
/**
* 根据主键值获取Entity的表名
*

View File

@@ -18,6 +18,8 @@ import org.redkale.convert.ConvertDisabled;
* 详情见: https://redkale.org
*
* @author zhangjx
*
* @since 2.8.0
*/
@SuppressWarnings("unchecked")
public class AnyValueWriter extends AnyValue {

View File

@@ -7,7 +7,7 @@ package org.redkale.util;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
/**
* 简单的xml读取器, 只读element节点信息其他信息(如: namespace、comment、docdecl等)都会丢弃
@@ -31,7 +31,7 @@ public class XmlReader {
protected int columnNumber;
protected BiFunction<String, String, String> attrFunc;
protected BinaryOperator<String> attrFunc;
private static class TagNode {
@@ -64,7 +64,7 @@ public class XmlReader {
this.limit = start + len - 1;
}
public XmlReader attrFunc(BiFunction<String, String, String> func) {
public XmlReader attrFunc(BinaryOperator<String> func) {
this.attrFunc = func;
return this;
}