diff --git a/src/org/redkale/source/DataJdbcSource.java b/src/org/redkale/source/DataJdbcSource.java index e47dfc5af..99dae2997 100644 --- a/src/org/redkale/source/DataJdbcSource.java +++ b/src/org/redkale/source/DataJdbcSource.java @@ -437,7 +437,7 @@ public class DataJdbcSource extends DataSqlSource { final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ps.setFetchSize(1); final ResultSet set = ps.executeQuery(); - T rs = set.next() ? info.getValue(selects, set) : null; + T rs = set.next() ? info.getEntityValue(selects, set) : null; set.close(); ps.close(); return CompletableFuture.completedFuture(rs); @@ -463,15 +463,7 @@ public class DataJdbcSource extends DataSqlSource { final ResultSet set = ps.executeQuery(); Serializable val = defValue; if (set.next()) { - if (attr.type() == byte[].class) { - Blob blob = set.getBlob(1); - if (blob != null) val = blob.getBytes(1, (int) blob.length()); - } else { - val = (Serializable) set.getObject(1); - if (val != null && !CharSequence.class.isAssignableFrom(attr.type()) && (val instanceof CharSequence)) { - val = info.jsonConvert.convertFrom(attr.genericType(), val.toString()); - } - } + val = info.getFieldValue(attr, set, 1); } set.close(); ps.close(); @@ -530,7 +522,7 @@ public class DataJdbcSource extends DataSqlSource { PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet set = ps.executeQuery(); while (set.next()) { - list.add(infoGetValue(info, sels, set)); + list.add(getEntityValue(info, sels, set)); } set.close(); ps.close(); @@ -562,7 +554,7 @@ public class DataJdbcSource extends DataSqlSource { int i = 0; while (set.next()) { i++; - list.add(info.getValue(sels, set)); + list.add(info.getEntityValue(sels, set)); if (limit <= i) break; } long total = list.size(); diff --git a/src/org/redkale/source/DataSqlSource.java b/src/org/redkale/source/DataSqlSource.java index 96e2b5348..daf9da454 100644 --- a/src/org/redkale/source/DataSqlSource.java +++ b/src/org/redkale/source/DataSqlSource.java @@ -166,8 +166,16 @@ public abstract class DataSqlSource extends AbstractService implement //查询一页数据 protected abstract CompletableFuture> querySheetDB(final EntityInfo info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node); - protected T infoGetValue(EntityInfo info, final SelectColumn sels, final ResultSet set) throws SQLException { - return info.getValue(sels, set); + protected T getEntityValue(EntityInfo info, final SelectColumn sels, final ResultSet set) throws SQLException { + return info.getEntityValue(sels, set); + } + + protected Serializable getFieldValue(EntityInfo info, Attribute attr, final ResultSet set, int index) throws SQLException { + return info.getFieldValue(attr, set, index); + } + + protected Serializable getFieldValue(EntityInfo info, Attribute attr, final ResultSet set) throws SQLException { + return info.getFieldValue(attr, set); } protected String createSQLOrderby(EntityInfo info, Flipper flipper) { diff --git a/src/org/redkale/source/EntityInfo.java b/src/org/redkale/source/EntityInfo.java index 08fefe4a7..bc3606ac0 100644 --- a/src/org/redkale/source/EntityInfo.java +++ b/src/org/redkale/source/EntityInfo.java @@ -1032,7 +1032,7 @@ public final class EntityInfo { * @return Entity对象 * @throws SQLException SQLException */ - protected T getValue(final SelectColumn sels, final ResultSet set) throws SQLException { + protected T getEntityValue(final SelectColumn sels, final ResultSet set) throws SQLException { T obj; Attribute[] attrs = this.queryAttributes; if (this.constructorParameters == null) { @@ -1057,10 +1057,14 @@ public final class EntityInfo { } protected Serializable getFieldValue(Attribute attr, final ResultSet set) throws SQLException { + return getFieldValue(attr, set, 0); + } + + protected Serializable getFieldValue(Attribute attr, final ResultSet set, int index) throws SQLException { final Class t = attr.type(); Serializable o; if (t == byte[].class) { - Blob blob = set.getBlob(this.getSQLColumn(null, attr.field())); + Blob blob = index > 0 ? set.getBlob(index) : set.getBlob(this.getSQLColumn(null, attr.field())); if (blob == null) { o = null; } else { //不支持超过2G的数据 @@ -1069,7 +1073,7 @@ public final class EntityInfo { if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o); } } else { - o = (Serializable) set.getObject(this.getSQLColumn(null, attr.field())); + o = (Serializable) (index > 0 ? set.getObject(index) : set.getObject(this.getSQLColumn(null, attr.field()))); CryptHandler cryptHandler = attr.attach(); if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o); if (t.isPrimitive()) {