Skip to content

Adding command for JPA Entity Classes from DB#3405

Closed
jhorvath wants to merge 1 commit intoapache:masterfrom
jhorvath:entity-from-db
Closed

Adding command for JPA Entity Classes from DB#3405
jhorvath wants to merge 1 commit intoapache:masterfrom
jhorvath:entity-from-db

Conversation

@jhorvath
Copy link
Member

@jhorvath jhorvath commented Jan 4, 2022

Adding command for creating JPA Entity Classes from DB to java.lsp.server

"MSG_EnterPackageName=Enter package name"
})
@ServiceProvider(service = CodeActionsProvider.class)
public class DBEntityFromTables extends CodeActionsProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not like reusing CodeActionsProvider for registering simple Command providers. Consider creating a new CommandProvider interface/abstract class for such purpose. The original CodeActionsProvider should extend/implement it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we talked about that, but I didn't get to that refactoring. So far it is not a public API ... I'd suggest to fire a JIRA issue for the refactoring & refactor all such usages (there are more of them) in a single refactoring PR. I volunteer :)

}
Lookup.getDefault().lookup(LspServerState.class).openedProjects().thenAccept((projects) -> {
if (projects.length > 0) {
createEntityClassesInProject(client, projects[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Question: if the command is invoked with an active editor focused: shouldn't we create the classes in the editor's project instead in the 1st opened one ? The order of projects in openedProjects may be rather random.
Of course provided that the LSP command arguments contain some URI etc to begin with.

return;
});
} catch (SQLException | IllegalArgumentException | DatabaseException ex) {
System.out.println(ex.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

make this client.showMessage instead, or use NotifyDescriptor + DialogDisplayer.getDefault().notify() that will be automagically remoted to the client.

return null;
}
Connection conn = connection.getJDBCConnection();
ResultSet rs = conn.getMetaData().getTables(conn.getCatalog(), conn.getSchema(), "%", new String[]{"TABLE", "VIEW"}); //NOI18N
Copy link
Member

Choose a reason for hiding this comment

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

This call eventually waits for the data from the JDBC connection; I'd suggest to run the DB query in a RequesProcessor so the LSP communication is not blocked. The behaviour depends on the DB location / network conditions.

EntitiesFromDBGenerator generator = new EntitiesFromDBGenerator(tables, true, packageName, sr[0], connection, prj, null);
ProgressContributor pc = BasicAggregateProgressFactory.createProgressContributor("entity"); //NOI18N
try {
generator.generate(pc);
Copy link
Member

Choose a reason for hiding this comment

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

Also potentially run inside LSP event loop (input box response is sent as a protocol response to the server). Please check and if so, run asynchronously. The ProgressContributor indicates that the code called runs for some time and reports progress - that won't work when LSP connection is blocked.

@jhorvath jhorvath closed this Apr 12, 2022
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.

3 participants