gpt4 book ai didi

java - java rxObservable 的结果集中没有聚合数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:52:34 24 4
gpt4 key购买 nike

我尝试调用存储过程 3 次。当我运行下面的代码时,上次调用存储过程的数据仅显示在 resultSet.getRows() 中。前两次调用存储过程的数据没有出现在结果集中。以下是我的代码。难道我做错了什么。谁能帮忙?

String currentPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
String priorPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
String todayPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
JsonArray jsonArray = new JsonArray();

database.dbObject().getConnectionObservable().subscribe(
connection -> {
Observable<ResultSet> resultSetObservable = connection.callWithParamsObservable(currentPeriod, new JsonArray().add(params.getString("testParams")),jsonArray ).
flatMap(result -> connection.callWithParamsObservable(priorPeriod, new JsonArray().add(params.getString("testParams")), jsonArray ).
flatMap(result -> connection.callWithParamsObservable(todayPeriod, new JsonArray().add(params.getString("testParams")),jsonArray );

resultSetObservable.subscribe(resultSet -> {
handler.handle(ReportUtils.parseSQLResult(resultSet.getRows()));
},error -> {
error.printStackTrace();
},connection::close);

},err -> {
err.printStackTrace();
}
);

最佳答案

您尝试做的事情可以通过使用 combineLatest 运算符来实现,该运算符给出所有可观察对象的结果(它将等待所有可观察对象给出结果)

引用 http://reactivex.io/documentation/operators/combinelatest.html

伪代码,

       String currentPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
String priorPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
String todayPeriod = String.format("{call %s.testProc(?)}", params.getJsonObject("databaseInfo").getString("dbName"));
JsonArray jsonArray = new JsonArray();


database.dbObject().getConnectionObservable().subscribe(
connection -> {
resultSetObservable = Observable.combineLatest(firstCall, secCall, thirdCall)
firstCall = connection.callWithParamsObservable(currentPeriod, new JsonArray().add(params.getString("testParams")),jsonArray )

secCall = result -> connection.callWithParamsObservable(priorPeriod, new JsonArray().add(params.getString("testParams")), jsonArray )

thirdCall = result -> connection.callWithParamsObservable(todayPeriod, new JsonArray().add(params.getString("testParams")),jsonArray )
resultSetObservable.subscribe(firstRes, secRes, thirdRes -> {
handler.handle(ReportUtils.parseSQLResult(resultSet.getRows()));
},error -> {
error.printStackTrace();
},connection::close);

},err -> {
err.printStackTrace();
}
);

关于java - java rxObservable 的结果集中没有聚合数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39523525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com