This commit is contained in:
redkale
2024-09-21 22:30:56 +08:00
parent 82d375b517
commit f51a52e895
2 changed files with 16 additions and 30 deletions

View File

@@ -216,32 +216,20 @@ public interface DataResultSet extends DataResultSetRow {
public static <T> Serializable getRowColumnValue(
DataResultSetRow row, Attribute<T, Serializable> attr, int index, String column) {
final Class t = attr.type();
Serializable o = null;
try {
if (t == byte[].class) {
Object blob = index > 0 ? row.getObject(index) : row.getObject(column);
if (blob == null) {
o = null;
} else { // 不支持超过2G的数据
// if (blob instanceof java.sql.Blob) {
// java.sql.Blob b = (java.sql.Blob) blob;
// try {
// o = b.getBytes(1, (int) b.length());
// } catch (Exception e) { //一般不会发生
// o = null;
// }
// } else {
o = (byte[]) blob;
// }
if (t == byte[].class) {
return (byte[]) (index > 0 ? row.getObject(index) : row.getObject(column));
} else {
Serializable o = (Serializable) (index > 0 ? row.getObject(index) : row.getObject(column));
if (o != null) {
if (t == String.class && o instanceof String) {
return o;
} else if ((t == Integer.class || t == int.class) && o instanceof Integer) {
return o;
} else if ((t == Long.class || t == long.class) && o instanceof Long) {
return o;
}
} else {
o = (Serializable) (index > 0 ? row.getObject(index) : row.getObject(column));
o = formatColumnValue(t, attr.genericType(), o);
}
} catch (Exception e) {
throw new SourceException(
row.getEntityInfo() + "." + attr.field() + ".value=" + o + ": " + e.getMessage(), e.getCause());
return formatColumnValue(t, attr.genericType(), o);
}
return o;
}
}

View File

@@ -483,19 +483,17 @@ public class EntityBuilder<T> {
Object[] cps = new Object[this.constructorParameters.length];
for (int i = 0; i < constructorAttrs.length; i++) {
Attribute<T, Serializable> attr = constructorAttrs[i];
if (attr == null) {
continue;
if (attr != null) {
cps[i] = getFieldValue(row, attr, ++index);
}
cps[i] = getFieldValue(row, attr, ++index);
}
obj = creator.create(cps);
}
if (unconstructorAttrs != null) {
for (Attribute<T, Serializable> attr : unconstructorAttrs) {
if (attr == null) {
continue;
if (attr != null) {
attr.set(obj, getFieldValue(row, attr, ++index));
}
attr.set(obj, getFieldValue(row, attr, ++index));
}
}
return obj;