Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clovergaze
Copy link
Contributor

  • provided the correct return type
  • extended the example

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

* provided the correct return type
* extended the example
@clovergaze
Copy link
Contributor Author

clovergaze commented Sep 12, 2020

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() &rarr; array
r.dbList() &rarr; DbList
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants