DataResultSetRow增加getColumnLabels方法

This commit is contained in:
Redkale
2022-12-05 19:44:07 +08:00
parent e781be25a0
commit 709d320a5a
3 changed files with 23 additions and 6 deletions

View File

@@ -1777,7 +1777,7 @@ public final class Application {
AnyValue old = findSourceConfig(name, "cachesource");
conf.forEach((k, v) -> {
events.add(ResourceEvent.create(k, v, old == null ? null : old.getValue(k)));
((DefaultAnyValue) old).setValue(k, v);
if (old != null) ((DefaultAnyValue) old).setValue(k, v);
});
((AbstractCacheSource) source).onChange(events.toArray(new ResourceEvent[events.size()]));
});
@@ -1791,7 +1791,7 @@ public final class Application {
AnyValue old = findSourceConfig(name, "datasource");
conf.forEach((k, v) -> {
events.add(ResourceEvent.create(k, v, old == null ? null : old.getValue(k)));
((DefaultAnyValue) old).setValue(k, v);
if (old != null) ((DefaultAnyValue) old).setValue(k, v);
});
((AbstractDataSource) source).onChange(events.toArray(new ResourceEvent[events.size()]));
});

View File

@@ -50,7 +50,7 @@ public class DataJdbcSource extends DataSqlSource {
@Override
public void onChange(ResourceEvent[] events) {
}
@Override
@@ -1040,6 +1040,21 @@ public class DataJdbcSource extends DataSqlSource {
}
}
@Override
public List<String> getColumnLabels() {
try {
ResultSetMetaData meta = rr.getMetaData();
int count = meta.getColumnCount();
List<String> labels = new ArrayList<>(count);
for (int i = 1; i <= count; i++) {
labels.add(meta.getColumnLabel(i));
}
return labels;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean wasNull() {
try {

View File

@@ -1393,15 +1393,17 @@ public final class EntityInfo<T> {
//index从1开始
public Object getObject(int index);
public Object getObject(String column);
public Object getObject(String columnLabel);
//index从1开始
default <T> Serializable getObject(Attribute<T, Serializable> attr, int index, String column) {
return DataResultSet.getRowColumnValue(this, attr, index, column);
default <T> Serializable getObject(Attribute<T, Serializable> attr, int index, String columnLabel) {
return DataResultSet.getRowColumnValue(this, attr, index, columnLabel);
}
//判断当前行值是否为null
public boolean wasNull();
public List<String> getColumnLabels();
}
public static class EntityColumn {