EntityBuilder优化
This commit is contained in:
@@ -8,6 +8,7 @@ import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.redkale.annotation.Nullable;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.persistence.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@@ -215,7 +216,7 @@ public class EntityBuilder<T> {
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public T getEntityValue(final Attribute<T, Serializable>[] constructorAttrs, final Attribute<T, Serializable>[] unconstructorAttrs, final EntityInfo.DataResultSetRow row) {
|
||||
protected T getEntityValue(final Attribute<T, Serializable>[] constructorAttrs, final Attribute<T, Serializable>[] unconstructorAttrs, final EntityInfo.DataResultSetRow row) {
|
||||
if (row.wasNull()) {
|
||||
return null;
|
||||
}
|
||||
@@ -254,7 +255,7 @@ public class EntityBuilder<T> {
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public T getEntityValue(final Attribute<T, Serializable>[] constructorAttrs, final Attribute<T, Serializable>[] unconstructorAttrs, final Serializable... values) {
|
||||
protected T getEntityValue(final Attribute<T, Serializable>[] constructorAttrs, final Attribute<T, Serializable>[] unconstructorAttrs, final Serializable... values) {
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -284,7 +285,7 @@ public class EntityBuilder<T> {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public Serializable getFieldValue(Attribute<T, Serializable> attr, final EntityInfo.DataResultSetRow row, int index) {
|
||||
protected Serializable getFieldValue(Attribute<T, Serializable> attr, final EntityInfo.DataResultSetRow row, int index) {
|
||||
return row.getObject(attr, index, index > 0 ? null : this.getSQLColumn(null, attr.field()));
|
||||
}
|
||||
|
||||
@@ -305,6 +306,17 @@ public class EntityBuilder<T> {
|
||||
return constructorAttributes != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Entity类的字段名与表字段名s是否存在不一致的值
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public boolean isNoAlias() {
|
||||
return this.aliasmap == null;
|
||||
}
|
||||
|
||||
@ConvertDisabled
|
||||
public Creator<T> getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@@ -88,10 +88,6 @@ public final class EntityInfo<T> {
|
||||
//存放所有与数据库对应的字段, 包括主键
|
||||
final Attribute<T, Serializable>[] attributes;
|
||||
|
||||
//key是field的name, value是Column的别名,即数据库表的字段名
|
||||
//只有field.name 与 Column.name不同才存放在aliasmap里.
|
||||
private final Map<String, String> aliasmap;
|
||||
|
||||
//所有可更新字段,即排除了主键字段和标记为@Column(updatable=false)的字段
|
||||
private final Map<String, Attribute<T, Serializable>> updateAttributeMap = new HashMap<>();
|
||||
|
||||
@@ -387,7 +383,7 @@ public final class EntityInfo<T> {
|
||||
}
|
||||
String[] constructorParameters = cps;
|
||||
Attribute idAttr0 = null;
|
||||
Map<String, String> aliasmap0 = null;
|
||||
Map<String, String> aliasmap = null;
|
||||
Class cltmp = type;
|
||||
Set<String> fields = new HashSet<>();
|
||||
List<String> queryCols = new ArrayList<>();
|
||||
@@ -421,10 +417,10 @@ public final class EntityInfo<T> {
|
||||
final Column col = field.getAnnotation(Column.class);
|
||||
final String sqlField = col == null || col.name().isEmpty() ? fieldName : col.name();
|
||||
if (!fieldName.equals(sqlField)) {
|
||||
if (aliasmap0 == null) {
|
||||
aliasmap0 = new HashMap<>();
|
||||
if (aliasmap == null) {
|
||||
aliasmap = new HashMap<>();
|
||||
}
|
||||
aliasmap0.put(fieldName, sqlField);
|
||||
aliasmap.put(fieldName, sqlField);
|
||||
}
|
||||
Attribute attr;
|
||||
try {
|
||||
@@ -494,7 +490,6 @@ public final class EntityInfo<T> {
|
||||
|
||||
this.primary = idAttr0;
|
||||
this.primaryOneArray = new Attribute[]{this.primary};
|
||||
this.aliasmap = aliasmap0;
|
||||
List<EntityColumn> ddls = new ArrayList<>();
|
||||
Collections.reverse(ddlList); //父类的字段排在前面
|
||||
for (List<EntityColumn> ls : ddlList) {
|
||||
@@ -1323,15 +1318,6 @@ public final class EntityInfo<T> {
|
||||
return this.updateAttributeMap.get(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Entity类的字段名与表字段名s是否存在不一致的值
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isNoAlias() {
|
||||
return this.aliasmap == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Flipper获取ORDER BY的SQL语句,不存在Flipper或sort字段返回空字符串
|
||||
*
|
||||
@@ -1353,7 +1339,7 @@ public final class EntityInfo<T> {
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(" ORDER BY ");
|
||||
if (isNoAlias()) {
|
||||
if (builder.isNoAlias()) {
|
||||
sb.append(sort);
|
||||
} else {
|
||||
boolean flag = false;
|
||||
@@ -1387,8 +1373,7 @@ public final class EntityInfo<T> {
|
||||
* @return String
|
||||
*/
|
||||
public String getSQLColumn(String tabalis, String fieldname) {
|
||||
return this.aliasmap == null ? (tabalis == null ? fieldname : (tabalis + '.' + fieldname))
|
||||
: (tabalis == null ? aliasmap.getOrDefault(fieldname, fieldname) : (tabalis + '.' + aliasmap.getOrDefault(fieldname, fieldname)));
|
||||
return builder.getSQLColumn(tabalis, fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user