This commit is contained in:
Redkale
2019-01-13 16:51:06 +08:00
parent 847f81374b
commit 6950eb2f30
3 changed files with 21 additions and 17 deletions

View File

@@ -437,7 +437,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ps.setFetchSize(1); ps.setFetchSize(1);
final ResultSet set = ps.executeQuery(); 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(); set.close();
ps.close(); ps.close();
return CompletableFuture.completedFuture(rs); return CompletableFuture.completedFuture(rs);
@@ -463,15 +463,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
final ResultSet set = ps.executeQuery(); final ResultSet set = ps.executeQuery();
Serializable val = defValue; Serializable val = defValue;
if (set.next()) { if (set.next()) {
if (attr.type() == byte[].class) { val = info.getFieldValue(attr, set, 1);
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());
}
}
} }
set.close(); set.close();
ps.close(); ps.close();
@@ -530,7 +522,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet set = ps.executeQuery(); ResultSet set = ps.executeQuery();
while (set.next()) { while (set.next()) {
list.add(infoGetValue(info, sels, set)); list.add(getEntityValue(info, sels, set));
} }
set.close(); set.close();
ps.close(); ps.close();
@@ -562,7 +554,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
int i = 0; int i = 0;
while (set.next()) { while (set.next()) {
i++; i++;
list.add(info.getValue(sels, set)); list.add(info.getEntityValue(sels, set));
if (limit <= i) break; if (limit <= i) break;
} }
long total = list.size(); long total = list.size();

View File

@@ -166,8 +166,16 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
//查询一页数据 //查询一页数据
protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node); protected abstract <T> CompletableFuture<Sheet<T>> querySheetDB(final EntityInfo<T> info, final boolean needtotal, final SelectColumn selects, final Flipper flipper, final FilterNode node);
protected <T> T infoGetValue(EntityInfo<T> info, final SelectColumn sels, final ResultSet set) throws SQLException { protected <T> T getEntityValue(EntityInfo<T> info, final SelectColumn sels, final ResultSet set) throws SQLException {
return info.getValue(sels, set); return info.getEntityValue(sels, set);
}
protected <T> Serializable getFieldValue(EntityInfo<T> info, Attribute<T, Serializable> attr, final ResultSet set, int index) throws SQLException {
return info.getFieldValue(attr, set, index);
}
protected <T> Serializable getFieldValue(EntityInfo<T> info, Attribute<T, Serializable> attr, final ResultSet set) throws SQLException {
return info.getFieldValue(attr, set);
} }
protected <T> String createSQLOrderby(EntityInfo<T> info, Flipper flipper) { protected <T> String createSQLOrderby(EntityInfo<T> info, Flipper flipper) {

View File

@@ -1032,7 +1032,7 @@ public final class EntityInfo<T> {
* @return Entity对象 * @return Entity对象
* @throws SQLException SQLException * @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; T obj;
Attribute<T, Serializable>[] attrs = this.queryAttributes; Attribute<T, Serializable>[] attrs = this.queryAttributes;
if (this.constructorParameters == null) { if (this.constructorParameters == null) {
@@ -1057,10 +1057,14 @@ public final class EntityInfo<T> {
} }
protected Serializable getFieldValue(Attribute<T, Serializable> attr, final ResultSet set) throws SQLException { protected Serializable getFieldValue(Attribute<T, Serializable> attr, final ResultSet set) throws SQLException {
return getFieldValue(attr, set, 0);
}
protected Serializable getFieldValue(Attribute<T, Serializable> attr, final ResultSet set, int index) throws SQLException {
final Class t = attr.type(); final Class t = attr.type();
Serializable o; Serializable o;
if (t == byte[].class) { 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) { if (blob == null) {
o = null; o = null;
} else { //不支持超过2G的数据 } else { //不支持超过2G的数据
@@ -1069,7 +1073,7 @@ public final class EntityInfo<T> {
if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o); if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o);
} }
} else { } 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(); CryptHandler cryptHandler = attr.attach();
if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o); if (cryptHandler != null) o = (Serializable) cryptHandler.decrypt(o);
if (t.isPrimitive()) { if (t.isPrimitive()) {