diff --git a/src/main/java/org/redkale/source/EntityBuilder.java b/src/main/java/org/redkale/source/EntityBuilder.java index d43a00d85..53c98445c 100644 --- a/src/main/java/org/redkale/source/EntityBuilder.java +++ b/src/main/java/org/redkale/source/EntityBuilder.java @@ -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 { * * @return Entity对象 */ - public T getEntityValue(final Attribute[] constructorAttrs, final Attribute[] unconstructorAttrs, final EntityInfo.DataResultSetRow row) { + protected T getEntityValue(final Attribute[] constructorAttrs, final Attribute[] unconstructorAttrs, final EntityInfo.DataResultSetRow row) { if (row.wasNull()) { return null; } @@ -254,7 +255,7 @@ public class EntityBuilder { * * @return Entity对象 */ - public T getEntityValue(final Attribute[] constructorAttrs, final Attribute[] unconstructorAttrs, final Serializable... values) { + protected T getEntityValue(final Attribute[] constructorAttrs, final Attribute[] unconstructorAttrs, final Serializable... values) { if (values == null) { return null; } @@ -284,7 +285,7 @@ public class EntityBuilder { return obj; } - public Serializable getFieldValue(Attribute attr, final EntityInfo.DataResultSetRow row, int index) { + protected Serializable getFieldValue(Attribute 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 { return constructorAttributes != null; } + /** + * 判断Entity类的字段名与表字段名s是否存在不一致的值 + * + * @return boolean + */ + @ConvertDisabled + public boolean isNoAlias() { + return this.aliasmap == null; + } + + @ConvertDisabled public Creator getCreator() { return creator; } diff --git a/src/main/java/org/redkale/source/EntityInfo.java b/src/main/java/org/redkale/source/EntityInfo.java index e65a5a4ce..2eca9c1c5 100644 --- a/src/main/java/org/redkale/source/EntityInfo.java +++ b/src/main/java/org/redkale/source/EntityInfo.java @@ -88,10 +88,6 @@ public final class EntityInfo { //存放所有与数据库对应的字段, 包括主键 final Attribute[] attributes; - //key是field的name, value是Column的别名,即数据库表的字段名 - //只有field.name 与 Column.name不同才存放在aliasmap里. - private final Map aliasmap; - //所有可更新字段,即排除了主键字段和标记为@Column(updatable=false)的字段 private final Map> updateAttributeMap = new HashMap<>(); @@ -387,7 +383,7 @@ public final class EntityInfo { } String[] constructorParameters = cps; Attribute idAttr0 = null; - Map aliasmap0 = null; + Map aliasmap = null; Class cltmp = type; Set fields = new HashSet<>(); List queryCols = new ArrayList<>(); @@ -421,10 +417,10 @@ public final class EntityInfo { 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 { this.primary = idAttr0; this.primaryOneArray = new Attribute[]{this.primary}; - this.aliasmap = aliasmap0; List ddls = new ArrayList<>(); Collections.reverse(ddlList); //父类的字段排在前面 for (List ls : ddlList) { @@ -1323,15 +1318,6 @@ public final class EntityInfo { 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 { } 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 { * @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); } /**