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

Adding command for New Database Connection #3358

Merged
merged 8 commits into from Dec 21, 2021

Conversation

jhorvath
Copy link
Contributor

@jhorvath jhorvath commented Dec 8, 2021

Adding command for New Database Connection to java.lsp.server

@sdedic sdedic requested review from dbalek and JaroslavTulach and removed request for dbalek December 8, 2021 17:11
@sdedic sdedic added enhancement LSP [ci] enable Language Server Protocol tests labels Dec 8, 2021
Copy link

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine at first round:

  • properly version the DB module API changes
  • avoid needless changes in platform.properties
  • write a test for the new method
  • try to avoid references to "Micronaut" in this generic extension

* @param dbconn
* @return List of schemas or null if connection failed
*/
public List<String> getSchemas(DatabaseConnection dbconn) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API change. It needs @since tag, it needs a note in apichanges.xml.

*/
public List<String> getSchemas(DatabaseConnection dbconn) {
if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("This method can not be called on the event dispatch thread."); // NOI18N

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot is a single word - maybe you want to spell this (unusual?) restriction in the Javadoc of the method.

* Retrieves a list of database schemas available for given connection.
*
* @param dbconn
* @return List of schemas or null if connection failed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use {@code null} to print it in a different font. Shouldn't an exception be raised if the connection fails?

}
}
}
} catch (DatabaseException | SQLException ex) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not propagate the exception to the caller?

java/java.lsp.server/nbcode/nbproject/platform.properties Outdated Show resolved Hide resolved
org.openide.options,\
org.openide.util.enumerations,\
org.openidex.util
nbjdk.active=JDK_11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid nbjdk.active and nbplatform.active.

@@ -858,6 +859,7 @@ protected LanguageClient client() {
public static final String JAVA_SUPER_IMPLEMENTATION = "java.super.implementation";
public static final String JAVA_SOURCE_FOR = "java.source.for";
public static final String GRAALVM_PAUSE_SCRIPT = "graalvm.pause.script";
public static final String DB_ADD_CONNECTION = "micronaut.add.db.connection";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this command prefixed by micronaut? The DB explorer is completely micronaut unrelated, right?

{
"command": "micronaut.add.db.connection",
"title": "Add Database Connection",
"category": "Micronaut"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better if Micronaut extension were in enterprise/micronaut module, not here.

java/java.lsp.server/vscode/src/nbcode.ts Show resolved Hide resolved
Copy link

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most recent version eliminates the API changes altogether, great! The "Add Database Connection" command looks fine to me. Please squash a bit to eliminate the add/remove of platform.properties entries and the API attempt from the history after merge.

java/java.lsp.server/nbcode/nbproject/platform.properties Outdated Show resolved Hide resolved
java/java.lsp.server/nbcode/nbproject/platform.properties Outdated Show resolved Hide resolved
java/java.lsp.server/vscode/package.json Show resolved Hide resolved
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, looks sane to me.

@matthiasblaesing
Copy link
Contributor

@jhorvath Before this is merged:

  • please ensure the author information is consistent, there is at least one merge commit, that only holds your username and a different email adress. I assume, this is created by github.
  • after final review, please rebase onto master and squash into one commit (this will most likely fix the author point)
  • I assume you read the license statement in the files you edited/added and you are in a position to donate the changes to the Apache Foundation and do so. (or you have an ICLA on file?)

@jhorvath
Copy link
Contributor Author

I have read and agree to the license statement.

FileObject jarFO = URLMapper.findFileObject(jars[0]);
if (jarFO != null && jarFO.isValid()) {
items.add(
new QuickPickItem(drivers[i].getName(), null, drivers[i].getDisplayName() + " (" + drivers[i].getClassName() + ")", false, i) // NOI18N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm; on the second thought, consider to send drivers[i].getName() to identify the selected driver in then clause. Not necessary, unless another vscode instance adds a driver.

}
client.showInputBox(new ShowInputBoxParams(
Bundle.MSG_EnterPassword(), "", true)).thenAccept((password) -> { //NOI18N
if (password == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is password required for all databases ? E.g. for mysql, password-less logins can be allowed (?)

return;
}
DatabaseConnection dbconn = DatabaseConnection.create(driver, u, username, null, password, true);
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like to limit that deep nesting, this is the point where the CompletableFuture can yield a DatabaseConnection instance and we can with thenAccept at top level again :)

ResultSet rs = dbMetaData.getSchemas();
if (rs != null) {
while (rs.next()) {
schemas.add(rs.getString(1).trim());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is index safer than column name in this case ?

java/java.lsp.server/vscode/src/protocol.ts Outdated Show resolved Hide resolved
@@ -756,7 +756,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
return selected ? Array.isArray(selected) ? selected : [selected] : undefined;
});
c.onRequest(InputBoxRequest.type, async param => {
return await window.showInputBox({ prompt: param.prompt, value: param.value });
return await window.showInputBox({ prompt: param.prompt, value: param.value, password: param.password });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump required spec version in nbcode/integration module.

@sdedic
Copy link
Member

sdedic commented Dec 21, 2021

I would ignore the commit validation on Mac. Failed on a timeout.

@sdedic sdedic merged commit 9dc2a2e into apache:master Dec 21, 2021
@neilcsmith-net neilcsmith-net added this to the NB13 milestone Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement LSP [ci] enable Language Server Protocol tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants