Adding command for JPA Entity Classes from DB#3405
Adding command for JPA Entity Classes from DB#3405jhorvath wants to merge 1 commit intoapache:masterfrom
Conversation
| "MSG_EnterPackageName=Enter package name" | ||
| }) | ||
| @ServiceProvider(service = CodeActionsProvider.class) | ||
| public class DBEntityFromTables extends CodeActionsProvider { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Adding command for creating JPA Entity Classes from DB to java.lsp.server