-
Notifications
You must be signed in to change notification settings - Fork 41
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
Oracle Warning Segments #98
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45bc3bf
Adding OracleR2dbcWarning
Michael-A-McMahon f05443c
Add Segment type for warnings
Michael-A-McMahon fbef5e2
Subtyping OracleR2dbcWarning as a Message
Michael-A-McMahon 32d364c
Granting CREATE VIEW to the test user
Michael-A-McMahon 496e75d
Updating documentation
Michael-A-McMahon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package oracle.r2dbc; | ||
|
||
import io.r2dbc.spi.R2dbcException; | ||
import io.r2dbc.spi.Result; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* <p> | ||
* A subtype of the {@link Result.Segment} interface that provides information | ||
* on warnings raised by Oracle Database. | ||
* </p><p> | ||
* When a SQL command results in a warning, Oracle R2DBC emits a {@link Result} | ||
* with an {@code OracleR2dbcWarning} segment in addition to any other segments | ||
* that resulted from the SQL command. For example, if a SQL {@code SELECT} | ||
* command results in a warning, then an {@code OracleR2dbcWarning} segment is | ||
* included with the result, along with any {@link Result.RowSegment}s returned | ||
* by the {@code SELECT}. | ||
* </p><p> | ||
* R2DBC drivers typically emit {@code onError} signals for {@code Message} | ||
* segments that are not consumed by {@link Result#filter(Predicate)} or | ||
* {@link Result#flatMap(Function)}. Oracle R2DBC does not apply this behavior | ||
* for warning messages. If an {@code OracleR2dbcWarning} | ||
* segment is not consumed by the {@code filter} or {@code flatMap} methods of | ||
* a {@code Result}, then the warning is discarded and the result may be | ||
* consumed as normal with with the {@code map} or {@code getRowsUpdated} | ||
* methods. | ||
* </p><p> | ||
* Warning messages may be consumed with {@link Result#flatMap(Function)}: | ||
* </p><pre>{@code | ||
* result.flatMap(segment -> { | ||
* if (segment instanceof OracleR2dbcWarning) { | ||
* logWarning(((OracleR2dbcWarning)segment).getMessage()); | ||
* return emptyPublisher(); | ||
* } | ||
* else { | ||
* ... handle other segment types ... | ||
* } | ||
* }) | ||
* }</pre><p> | ||
* A {@code flatMap} function may also be used to convert a warning into an | ||
* {@code onError} signal: | ||
* </p><pre>{@code | ||
* result.flatMap(segment -> { | ||
* if (segment instanceof OracleR2dbcWarning) { | ||
* return errorPublisher(((OracleR2dbcWarning)segment).warning()); | ||
* } | ||
* else { | ||
* ... handle other segment types ... | ||
* } | ||
* }) | ||
* }</pre> | ||
* @since 1.1.0 | ||
*/ | ||
public interface OracleR2dbcWarning extends Result.Segment { | ||
|
||
/** | ||
* Returns the warning as an {@link R2dbcException}. | ||
* @return The warning as an {@link R2dbcException}. Not null. | ||
*/ | ||
R2dbcException exception(); | ||
|
||
/** | ||
* Returns the error code of the warning. | ||
* @return The error code of the warning. | ||
*/ | ||
int errorCode(); | ||
|
||
/** | ||
* Returns the SQLState of the warning. | ||
* @return The SQLState of the warning. Not null. | ||
*/ | ||
String sqlState(); | ||
|
||
/** | ||
* Returns the text of the warning message. | ||
* @return The text of the warning message. Not null. | ||
*/ | ||
String message(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extending
Result.Message
would likely make more sense to pick up what's already provided by the spec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciate you joining in on this!
I can see how a Message subtype is much easier to work with, and I'm happy to make that change.
Would you be open to adding an
instanceof OracleR2dbcWarning
check in Spring then? Users are telling me that they don't want warnings to be emitted as onError signals. So if Spring has aninstanceof Message
check that results in onError, we'd want to avoid taking that branch.The main goal is to make warnings an "opt-in" type of result. That is, code which consumes a
Result
should not see a warning unless it explicitly checks for it. It is similar to JDBC'sgetWarnings
methods, where code won't see the warning unless it checks. To this end, calls toResult.getRowsUpdated
orResult.map
methods would not emit onError for warnings, even if the segment type is aResult.Message
subtype.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that emitting warnings as errors creates a lot of inconvenience in the first place.
I also understand the desire to inform users that something unexpected has happened that didn't immediately lead to failure. Most other drivers do not emit warnings as errors but rather allow consumption of warning (message) segments when users are interested in such detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying on this; Knowing that other drivers handle it this way is very helpful!
I've made the suggested changes.