diff --git a/enterprise/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/DbUtil.java b/enterprise/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/DbUtil.java index ac5c78a9a261..f5dafdf696bd 100644 --- a/enterprise/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/DbUtil.java +++ b/enterprise/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/db/DbUtil.java @@ -81,7 +81,7 @@ public static Map normalizePoolMap(Map poolValue String password = poolValues.get(__Password); String user = poolValues.get(__User); - if (driverClassName.indexOf("pointbase") != -1) { + if (driverClassName != null && driverClassName.indexOf("pointbase") != -1) { url = poolValues.get(__DatabaseName); } // Search for server name key should be case insensitive. diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties index a2a96ad27281..5c71586c9553 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties @@ -66,6 +66,9 @@ ACSD_SelectedTables=List of selected tables scanning-in-progress=Scanning in progress... LBL_DB_VIEW=(view) WRN_Server_Does_Not_Support_DS=This server does not support Data Sources. Please specify database connection instead. +LBL_LocalDatasource=&Local Data Source: +LBL_RemoteDatasource=&Server Data Source: +LBL_SchemaDatasource=&Database Schema: # EntityClassesPanel LBL_SpecifyEntityClassNames=Specify the names and the location of the entity classes. diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.form b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.form index 6457c87d270f..dd82f2bf355c 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.form +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.form @@ -47,7 +47,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -77,38 +77,69 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + @@ -118,7 +149,7 @@ - + @@ -126,7 +157,7 @@ - + @@ -142,7 +173,7 @@ - + @@ -410,7 +441,7 @@ - + diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.java b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.java index 6af7ecc6881d..cd6cc2c1d0e2 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.java +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.java @@ -28,7 +28,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; @@ -137,24 +139,17 @@ private void initSubComponents(){ if (project != null && ProviderUtil.isValidServerInstanceOrNone(project)) { // stop listening once a server was set serverStatusProvider.removeChangeListener(changeListener); - if (!Util.isContainerManaged(project)) { - // if selected server does not support DataSource then - // swap the combo to DB Connection selection - datasourceComboBox.setModel(new DefaultComboBoxModel()); - initializeWithDbConnections(); - // notify user about result of server selection: - DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(DatabaseTablesPanel.class, "WRN_Server_Does_Not_Support_DS"))); - } else { - // #190671 - because of hacks around server set in maven - // listen and update data sources after server was set here again. - // In theory this should not be necessary and - // j2ee.common.DatasourceUIHelper.performServerSelection should have done - // everything necessary but often at that time - // PersistenceProviderSupplier.supportsDefaultProvider() is still false - // (server change was not propagated there yet). In worst case combo model will be set twice: - datasourceComboBox.setModel(new DefaultComboBoxModel()); - initializeWithDatasources(); - } + datasourceLocalComboBox.setModel(new DefaultComboBoxModel()); + initializeWithDbConnections(); + // #190671 - because of hacks around server set in maven + // listen and update data sources after server was set here again. + // In theory this should not be necessary and + // j2ee.common.DatasourceUIHelper.performServerSelection should have done + // everything necessary but often at that time + // PersistenceProviderSupplier.supportsDefaultProvider() is still false + // (server change was not propagated there yet). In worst case combo model will be set twice: + datasourceServerComboBox.setModel(new DefaultComboBoxModel()); + initializeWithDatasources(); } }; @@ -171,24 +166,22 @@ private void initSubComponents(){ boolean canServerBeSelected = ProviderUtil.canServerBeSelected(project); { - boolean withDatasources = Util.isContainerManaged(project) || Util.isEjb21Module(project); - if ((withDatasources && serverIsSelected) || (canServerBeSelected && !serverIsSelected)) { - initializeWithDatasources(); - } else { - initializeWithDbConnections(); - } + boolean hasJPADataSourcePopulator = project.getLookup().lookup(JPADataSourcePopulator.class) != null; + initializeWithDatasources(); + initializeWithDbConnections(); DBSchemaUISupport.connect(dbschemaComboBox, dbschemaFileList); boolean hasDBSchemas = (dbschemaComboBox.getItemCount() > 0 && dbschemaComboBox.getItemAt(0) instanceof FileObject); dbschemaRadioButton.setEnabled(hasDBSchemas); - dbschemaComboBox.setEnabled(hasDBSchemas); dbschemaRadioButton.setVisible(hasDBSchemas); + dbschemaComboBox.setEnabled(hasDBSchemas); dbschemaComboBox.setVisible(hasDBSchemas); - datasourceLabel.setVisible(!hasDBSchemas); - datasourceRadioButton.setVisible(hasDBSchemas); + datasourceLocalRadioButton.setVisible(hasDBSchemas || hasJPADataSourcePopulator); + datasourceServerRadioButton.setVisible(hasJPADataSourcePopulator); + datasourceServerRadioButton.setEnabled(hasJPADataSourcePopulator); - selectDefaultTableSource(tableSource, withDatasources, project, targetFolder); + selectDefaultTableSource(tableSource, hasJPADataSourcePopulator, project, targetFolder); } // hack to ensure the progress dialog displayed by updateSourceSchema() @@ -205,21 +198,17 @@ private void initInitial(){ dbschemaComboBox.setEnabled(false); dbschemaRadioButton.setVisible(false); dbschemaComboBox.setVisible(false); - datasourceRadioButton.setVisible(false); + datasourceServerRadioButton.setVisible(false); org.openide.awt.Mnemonics.setLocalizedText(datasourceLabel, org.openide.util.NbBundle.getMessage(DatabaseTablesPanel.class, "LBL_Wait")); } private void initializeWithDatasources() { - org.openide.awt.Mnemonics.setLocalizedText(datasourceRadioButton, org.openide.util.NbBundle.getMessage(DatabaseTablesPanel.class, "LBL_Datasource")); - org.openide.awt.Mnemonics.setLocalizedText(datasourceLabel, org.openide.util.NbBundle.getMessage(DatabaseTablesPanel.class, "LBL_Datasource")); JPADataSourcePopulator dsPopulator = project.getLookup().lookup(JPADataSourcePopulator.class); - dsPopulator.connect(datasourceComboBox); + dsPopulator.connect(datasourceServerComboBox); } private void initializeWithDbConnections() { - org.openide.awt.Mnemonics.setLocalizedText(datasourceRadioButton, org.openide.util.NbBundle.getMessage(DatabaseTablesPanel.class, "LBL_JDBCConnection")); - org.openide.awt.Mnemonics.setLocalizedText(datasourceLabel, org.openide.util.NbBundle.getMessage(DatabaseTablesPanel.class, "LBL_JDBCConnection")); - DatabaseExplorerUIs.connect(datasourceComboBox, ConnectionManager.getDefault()); + DatabaseExplorerUIs.connect(datasourceLocalComboBox, ConnectionManager.getDefault()); } /** @@ -261,20 +250,16 @@ private void selectDefaultTableSource(TableSource tableSource, boolean withDatas // if the previous source was a data source, it should be selected // only if a database connection can be found for it and we can // connect to that connection without displaying a dialog - if (withDatasources) { - if (selectDatasource(tableSourceName, false)) { - return; - } + if (withDatasources && selectDatasource(tableSourceName, false)) { + return; } break; case CONNECTION: // if the previous source was a database connection, it should be selected // only if we can connect to it without displaying a dialog - if (!withDatasources) { - if (selectDbConnection(tableSourceName)) { - return; - } + if (selectDbConnection(tableSourceName)) { + return; } break; @@ -322,7 +307,7 @@ private void selectDefaultTableSource(TableSource tableSource, boolean withDatas //try to find jdbc connection DatabaseConnection cn = ProviderUtil.getConnection(pu); if(cn != null){ - datasourceComboBox.setSelectedItem(cn); + datasourceServerComboBox.setSelectedItem(cn); } } } @@ -331,7 +316,7 @@ private void selectDefaultTableSource(TableSource tableSource, boolean withDatas // nothing got selected so far, so select the data source / connection // radio button, but don't select an actual data source or connection // (since this would cause the connect dialog to be displayed) - datasourceRadioButton.setSelected(true); + datasourceServerRadioButton.setSelected(true); } /** @@ -349,21 +334,26 @@ private static List findDatabaseConnections(JPADataSource da if (datasource == null) { throw new NullPointerException("The datasource parameter cannot be null."); // NOI18N } + + List result = new ArrayList<>(); + String databaseUrl = datasource.getUrl(); String user = datasource.getUsername(); - if (databaseUrl == null || user == null) { - return Collections.emptyList(); - } - List result = new ArrayList<>(); for (DatabaseConnection dbconn : ConnectionManager.getDefault().getConnections()) { - if (databaseUrl.equals(dbconn.getDatabaseURL()) && user.equals(dbconn.getUser())) { + if (databaseUrl.equals(dbconn.getDatabaseURL())) { result.add(dbconn); } } - if (!result.isEmpty()) { - return Collections.unmodifiableList(result); + + List resultUserMatched = result + .stream() + .filter(dc -> Objects.equals(user, dc.getUser())) + .collect(Collectors.toList()); + + if(! resultUserMatched.isEmpty()) { + return resultUserMatched; } else { - return Collections.emptyList(); + return Collections.unmodifiableList(result); } } @@ -403,12 +393,14 @@ private boolean selectDatasource(String jndiName, boolean skipChecks) { } } boolean selected = false; - for(int i=0; i