-
Notifications
You must be signed in to change notification settings - Fork 43
R2DBC treating warning as exception #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @rathoreamrsingh, this issue identifies a problem with Oracle R2DBC: We don't have a way to filter warnings. To correct this, I'll need to declare a new interface: With this interface, user code we be able to filter warnings like this: result.filter(segment -> !(segment instanceof OracleR2dbcWarning)) I'll hope to find time for making this fix soon. |
As a temporary workaround, you might checking for a SQLWarning as a cause: result.filter(segment ->
!(segment instance of Result.Message)
|| !(((Result.Message)segment).exception().getCause() instanceof SQLWarning)) This is ugly though. I'll still want to make the proposed fix. |
Hi @Michael-A-McMahon |
Hi @Michael-A-McMahon, |
Hi @rathoreamrsingh, looks like I typed some code that didn't compile ("instance of"). Below is a full class that does compile (note the TODOs): import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.Result;
import reactor.core.publisher.Flux;
import java.sql.SQLWarning;
import java.time.Duration;
import java.time.LocalDateTime;
public class Warning {
public static void main(String[] args) {
Flux.usingWhen(
ConnectionFactories.get(
// TODO: Change URL for your database
"r2dbc:oracle://host:port/service-name")
.create(),
connection ->
Flux.from(connection.createStatement(
// TODO: Change <View_Name> to your view name
"SELECT * from <View_Name> WHERE DATA_DT >= :P0_startDate AND DATA_DT <=:P1_endDate")
.bind(0, LocalDateTime.now().minus(Duration.ofDays(2)))
.bind(1, LocalDateTime.now().minus(Duration.ofDays(1)))
.execute())
.flatMap(result ->
result.filter(segment -> !isWarning(segment))
.getRowsUpdated()),
Connection::close)
.toStream()
.forEach(System.out::println);
}
/**
* @return {@code true} if a result Segment is a warning, or {@code false} if
* not
*/
private static boolean isWarning(Result.Segment segment) {
if (!(segment instanceof Result.Message))
return false;
Result.Message message = (Result.Message) segment;
return message.exception().getCause() instanceof SQLWarning;
}
} |
Thanks a lot for the update. |
I have some code written to add the OracleR2dbcWarning class, and it seems to be working well. I've just noticed that this issue was originally spotted in #82, but I failed to recognize it at the time. So multiple programmers are having an issue with this: That's is a good indication that Oracle R2DBC is doing something wrong :( I'm thinking the right thing to do is to make warnings an "opt-in" feature, rather than "opt-out". Looking at JDBC, warnings are "opt-in": They are not thrown from methods that execute SQL. Instead, you may "opt-in" by calling a I think we'd all be happier if Oracle R2DBC were to follow the same model. You may opt-in to receiving warnings by calling Any thoughts about this? I hope this will be an improvement, but please let me know if you have other ideas. |
This seems to be a good solution to me. |
Hi,
I am using R2DBC with oracle, where I am trying to get some details from a view.
This view is having some warning while executing it which is not an exception but R2DBC is treating that as exception and is failing.
If I run the exact same query with limit of 9 or less records it works fine.
I tried this view with Spring data JPA and there it works perfectly fine.
Database used in this case is Oracle
Please have a look on this below log for more details.
Originally raised on spring-projects/spring-data-r2dbc#784
The text was updated successfully, but these errors were encountered: