mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
refactor: optimize
This commit is contained in:
parent
8c39797eac
commit
198569e743
@ -36,12 +36,14 @@ public class QueryTable implements CloneSupport<QueryTable> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public QueryTable(TableDef tableDef) {
|
public QueryTable(TableDef tableDef) {
|
||||||
this.name = tableDef.getTableName();
|
|
||||||
this.schema = tableDef.getSchema();
|
this.schema = tableDef.getSchema();
|
||||||
|
this.name = tableDef.getTableName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryTable(String name) {
|
public QueryTable(String name) {
|
||||||
this.name = StringUtil.tryTrim(name);
|
String[] schemaAndTableName = StringUtil.getSchemaAndTableName(name);
|
||||||
|
this.schema = schemaAndTableName[0];
|
||||||
|
this.name = schemaAndTableName[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryTable(String schema, String name) {
|
public QueryTable(String schema, String name) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据实体类对象,构建查询条件
|
* 根据实体类对象,构建查询条件
|
||||||
|
*
|
||||||
* @param entity 实体类对象
|
* @param entity 实体类对象
|
||||||
* @return 查询对象
|
* @return 查询对象
|
||||||
*/
|
*/
|
||||||
@ -133,15 +134,8 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
|||||||
if (StringUtil.isBlank(table)) {
|
if (StringUtil.isBlank(table)) {
|
||||||
throw new IllegalArgumentException("table must not be null or blank.");
|
throw new IllegalArgumentException("table must not be null or blank.");
|
||||||
}
|
}
|
||||||
int indexOf = table.indexOf(".");
|
|
||||||
if (indexOf > 0) {
|
|
||||||
String schema = table.substring(0, indexOf);
|
|
||||||
table = table.substring(indexOf + 1);
|
|
||||||
from(new QueryTable(schema, table));
|
|
||||||
} else {
|
|
||||||
from(new QueryTable(table));
|
from(new QueryTable(table));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ public class TableDefs implements Serializable {
|
|||||||
return Modifier.isPublic(mod) && Modifier.isStatic(mod);
|
return Modifier.isPublic(mod) && Modifier.isStatic(mod);
|
||||||
}).get(null);
|
}).get(null);
|
||||||
|
|
||||||
String key = StringUtil.isNotBlank(tableDef.getSchema()) ? tableDef.getSchema() + "." + tableDef.getTableName() : tableDef.getTableName();
|
String key = StringUtil.buildSchemaWithTable(tableDef.getSchema(), tableDef.getTableName());
|
||||||
|
|
||||||
TABLE_DEF_MAP.put(key, tableDef);
|
TABLE_DEF_MAP.put(key, tableDef);
|
||||||
|
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public class TableInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getTableNameWithSchema() {
|
public String getTableNameWithSchema() {
|
||||||
return StringUtil.isNotBlank(schema) ? schema + "." + tableName : tableName;
|
return StringUtil.buildSchemaWithTable(schema, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWrapSchemaAndTableName(IDialect dialect) {
|
public String getWrapSchemaAndTableName(IDialect dialect) {
|
||||||
@ -863,7 +863,7 @@ public class TableInfo {
|
|||||||
|
|
||||||
MetaObject metaObject = EntityMetaObject.forObject(entity, reflectorFactory);
|
MetaObject metaObject = EntityMetaObject.forObject(entity, reflectorFactory);
|
||||||
propertyColumnMapping.forEach((property, column) -> {
|
propertyColumnMapping.forEach((property, column) -> {
|
||||||
if (column.equals(logicDeleteColumn)){
|
if (column.equals(logicDeleteColumn)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object value = metaObject.getValue(property);
|
Object value = metaObject.getValue(property);
|
||||||
@ -871,6 +871,8 @@ public class TableInfo {
|
|||||||
QueryColumn queryColumn = TableDefs.getQueryColumn(entityClass, tableNameWithSchema, column);
|
QueryColumn queryColumn = TableDefs.getQueryColumn(entityClass, tableNameWithSchema, column);
|
||||||
if (queryColumn != null) {
|
if (queryColumn != null) {
|
||||||
queryWrapper.and(queryColumn.eq(value));
|
queryWrapper.and(queryColumn.eq(value));
|
||||||
|
} else {
|
||||||
|
queryWrapper.and(QueryMethods.column(tableNameWithSchema, column).eq(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -273,6 +273,16 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String buildSchemaWithTable(String schema, String tableName) {
|
||||||
|
return isNotBlank(schema) ? schema + "." + tableName : tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getSchemaAndTableName(String tableNameWithSchema) {
|
||||||
|
int index = tableNameWithSchema.indexOf(".");
|
||||||
|
return index <= 0 ? new String[]{null, tableNameWithSchema.trim()}
|
||||||
|
: new String[]{tableNameWithSchema.substring(0, index).trim(), tableNameWithSchema.substring(index + 1).trim()};
|
||||||
|
}
|
||||||
|
|
||||||
public static String tryTrim(String string) {
|
public static String tryTrim(String string) {
|
||||||
return string != null ? string.trim() : null;
|
return string != null ? string.trim() : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user