From 1d559ef4d440b34ef766b3768a10217966da41e5 Mon Sep 17 00:00:00 2001 From: Redkale Date: Tue, 17 Jan 2023 12:06:11 +0800 Subject: [PATCH] =?UTF-8?q?EntityInfo=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redkale/source/EntityInfo.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/org/redkale/source/EntityInfo.java b/src/main/java/org/redkale/source/EntityInfo.java index 886387a20..5d9962324 100644 --- a/src/main/java/org/redkale/source/EntityInfo.java +++ b/src/main/java/org/redkale/source/EntityInfo.java @@ -1642,6 +1642,10 @@ public final class EntityInfo { return getEntityValue(constructorAttributes, constructorAttributes == null ? queryAttributes : unconstructorAttributes, row); } + public T getFullEntityValue(final Serializable... values) { + return getEntityValue(constructorAttributes, constructorAttributes == null ? queryAttributes : unconstructorAttributes, values); + } + /** * 将一行的ResultSet组装成一个Entity对象 * @@ -1681,6 +1685,45 @@ public final class EntityInfo { return obj; } + /** + * 将一行的ResultSet组装成一个Entity对象 + * + * @param constructorAttrs 构建函数的Attribute数组, 大小必须与this.constructorAttributes相同 + * @param unconstructorAttrs 非构建函数的Attribute数组 + * @param values 字段值集合 + * + * @return Entity对象 + */ + protected T getEntityValue(final Attribute[] constructorAttrs, final Attribute[] unconstructorAttrs, final Serializable... values) { + if (values == null) { + return null; + } + T obj; + int index = -1; + if (this.constructorParameters == null) { + obj = creator.create(); + } else { + Object[] cps = new Object[this.constructorParameters.length]; + for (int i = 0; i < constructorAttrs.length; i++) { + Attribute attr = constructorAttrs[i]; + if (attr == null) { + continue; + } + cps[i] = values[++index]; + } + obj = creator.create(cps); + } + if (unconstructorAttrs != null) { + for (Attribute attr : unconstructorAttrs) { + if (attr == null) { + continue; + } + attr.set(obj, values[++index]); + } + } + return obj; + } + protected Serializable getFieldValue(Attribute attr, final DataResultSetRow row, int index) { return row.getObject(attr, index, index > 0 ? null : this.getSQLColumn(null, attr.field())); }