-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Adjusted documentation of dbList command (Java) #1289
base: master
Are you sure you want to change the base?
Conversation
* provided the correct return type * extended the example
This might also be a viable example: try (Result<Object> result = r.dbList().run(connection)) {
result.forEach(list -> {
((List<?>) list).forEach(System.out::println);
});
} |
r.dbList() → array | ||
r.dbList() → DbList |
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.
The return type should be array
. The types in this section refer to ReQL types, not Java types.
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.
Okay, I will revert that.
r.dbList().run(conn); | ||
List<?> dbList = r.dbList().run(connection, ArrayList.class).single(); | ||
|
||
if (dbList != null) { |
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'm not familiar with the Java driver, but I think dbList will never be null. Unless RethinkDB returns a nil result.
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.
In this example, my IDE (IntelliJ IDEA) complained that forEach
could produce a NullPointerException
and suggested adding this check.
In the end I did something more like this:
final Result<?> result = r.dbList().run(connection, List.class);
try (result) {
List<?> databaseList = (List<?>) result.single();
if (databaseList != null) {
databaseList.forEach(System.out::println);
}
}
So, maybe that should be the example code? People can still leave out anything they do not want or rewrite it according to their needs. My thought was just to provide a hint on how to use it. And maybe a more elaborated example could also lower the hurdle for new developers, to see how they could use it.
But of course the provided example should show a somewhat recommended way. For me r.dbList().run(conn);
was not really that sufficient or telling and this is what I thought could have helped me in the first place to get to use it more quickly. This is code I use because it is robust, but any suggestions are welcome.. I am referring to the new code above.
Reason for the change
I tried to get the list of database names from the server and the current documentation is not helpful in that regard. The specified return type is wrong and the array with database names had to be extracted from the
Result<Object>
.Description
I corrected the return type and added a useful example that shows how to get the database names.
Checklist