Skip to content

Commit

Permalink
Various small UI improvements to the database module's "New Connectio…
Browse files Browse the repository at this point in the history
…n" wizard.

Details:
* Improve two error messages in "New Connection" wizard.
* Avoid a spurious 'Specified class is not a driver' warning in certain situations.
* When detecting the Microsoft SQL Server JDBC driver, avoid showing an ancient version number.
* Add a default port number for Microsoft SQL Server.
* Decrease the timeout of the connection validation step.
  • Loading branch information
eirikbakke committed May 22, 2021
1 parent 5a34cc3 commit 2cea3bf
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ SchemaIsNotSet=Default schema

EXC_InsufficientConnInfo=insufficient information to create a connection
# {0} is database URL, {1} is the database driver name, {2} is additional info
EXC_CannotEstablishConnection=Cannot establish a connection to {0} using {1} ({2})
# The "New Connection Wizard" only has space for the first part of the message, so put the message
# from the driver (parameter {2}), which usually explains the error, first.
EXC_CannotEstablishConnection=Connection failed: {2} ({0} using {1})

# {0} is a user provided value
EXC_CannotOperateWith=Cannot operate with {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public void setDriver(JDBCDriver drv) {
String fileName = null;
dlm.clear();
drvs.clear();
jarClassLoader = null;
URL[] urls = drv == null ? new URL[0] : drv.getURLs();
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
Expand Down Expand Up @@ -379,6 +380,7 @@ private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
if (lsm.isSelectedIndex(i)) {
dlm.remove(i);
drvs.remove(i);
jarClassLoader = null;
count--;
continue;
}
Expand Down Expand Up @@ -431,6 +433,7 @@ public String getDescription() {
dlm.addElement(file.toString());
try {
drvs.add(file.toURI().toURL());
jarClassLoader = null;
} catch (MalformedURLException exc) {
LOGGER.log(Level.WARNING,
"Unable to add driver jar file " +
Expand Down Expand Up @@ -603,10 +606,11 @@ public void run() {
}

private URLClassLoader getJarClassLoader() {
// This classloader is used to load classes
// from the jar files for the driver. We can then use
// introspection to see if a class in one of these jar files
// implements java.sql.Driver
/* This classloader is used to load classes from the jar files for the driver. We can then
introspection to see if a class in one of these jar files implements java.sql.Driver. (We
clear the jarClassLoader whenever drvs is modified, to avoid the AddDriverNotJavaSqlDriver
message popping up if a different driver is picked from the dropdown after an unrelated JAR
file is added.) */
jarClassLoader =
new URLClassLoader(drvs.toArray(new URL[drvs.size()]),
this.getClass().getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void exceptionOccurred(Exception exc) {

databaseConnection.addExceptionListener(excListener);
databaseConnection.connectAsync();
int maxLoops = 60;
int maxLoops = 20;
int loop = 0;
while (loop < maxLoops) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,14 @@ void checkValid() {
for (Entry<String, UrlField> entry : urlFields.entrySet()) {
if (url.requiresToken(entry.getKey()) && isEmpty(entry.getValue().getField().getText())) {
requiredFieldMissing = true;
String fieldName = entry.getValue().getLabel().getText();
/* Drop the colon, since this message goes at the bottom of the wizard dialog (e.g. avoid
the message looking like "Please specify a value for TNS Name:"). */
if (fieldName.endsWith(":")) {
fieldName = fieldName.substring(0, fieldName.length() - 1);
}
displayMessage(NbBundle.getMessage(NewConnectionPanel.class, "NewConnection.ERR_FieldRequired",
entry.getValue().getLabel().getText()), false);
fieldName), false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ide/db/src/org/netbeans/modules/db/util/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ DRIVERNAME_OracleThin=Oracle Thin
DRIVERNAME_OracleOCI=Oracle OCI
DRIVERNAME_JTDS=jTDS
DRIVERNAME_DB2JCC=IBM DB2 Universal Driver
DRIVERNAME_MSSQL2005=Microsoft SQL Server 2005
DRIVERNAME_MSSQL=Microsoft SQL Server

# Map JDBC URL token identifiers to human-readable strings
<HOST>=Host
Expand Down
5 changes: 4 additions & 1 deletion ide/db/src/org/netbeans/modules/db/util/DriverListUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ private static JdbcUrl add(String name, String driverClassName, String urlTempla
"com.microsoft.jdbc.sqlserver.SQLServerDriver",
"jdbc:microsoft:sqlserver://<HOST>[:<PORT>][;DatabaseName=<DB>]");

add(NbBundle.getMessage(DriverListUtil.class, "DRIVERNAME_MSSQL2005"),
/* Previously we used to say "Microsoft SQL Server 2005" here, but as of driver version 7.2.2
(latest per July 2019), the class name is still the same. So don't say "2005" anymore. */
url = add(NbBundle.getMessage(DriverListUtil.class, "DRIVERNAME_MSSQL"),
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[<HOST>[\\<INSTANCE>][:<PORT>]][;databaseName=<DB>][;<ADDITIONAL>]", true);
url.setSampleUrl("jdbc:sqlserver://localhost:1433");

url = add(NbBundle.getMessage(DriverListUtil.class, "DRIVERNAME_MySQL"),
"com.mysql.cj.jdbc.Driver",
Expand Down
17 changes: 13 additions & 4 deletions ide/db/src/org/netbeans/modules/db/util/JdbcUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,19 @@ public String getDisplayName() {
nameAndType = displayName + " (" + getType() + ")"; //NOI18N
}
if (driver != null && driver.getDisplayName() != null
&& !driver.getDisplayName().equals(displayName)) {
return NbBundle.getMessage(DriverListUtil.class,
"JDBC_URL_DRIVER_NAME", //NOI18N
nameAndType, driver.getDisplayName());
&& !driver.getDisplayName().equals(displayName))
{
/* If the driver name has been customized such that
JDBC_URL_DRIVER_NAME format would yield, for instance,
"Oracle Thin / Service ID (SID) on Oracle", then we can just drop
the "on Oracle" part. */
if (nameAndType.startsWith(driver.getDisplayName())) {
return nameAndType;
} else {
return NbBundle.getMessage(DriverListUtil.class,
"JDBC_URL_DRIVER_NAME", //NOI18N
nameAndType, driver.getDisplayName());
}
} else {
return nameAndType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static junit.framework.Assert.assertEquals;
import junit.framework.TestCase;
import org.netbeans.api.db.explorer.JDBCDriver;
import org.openide.util.NbBundle;
Expand Down Expand Up @@ -350,7 +349,7 @@ private void testJTDS(JTDSTypes type) throws Exception {

public void testMSSQL2005() throws Exception {
/*
add(getMessage("DRIVERNAME_MSSQL2005"),
add(getMessage("DRIVERNAME_MSSQL"),
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[<HOST>[\\<INSTANCE>][:<PORT>]][;databaseName=<DB>][;<ADDITIONAL>]", true);
*/
Expand All @@ -359,7 +358,7 @@ public void testMSSQL2005() throws Exception {
supportedProps.add(JdbcUrl.TOKEN_INSTANCE);

ArrayList<String> requiredProps = new ArrayList<String>();
JdbcUrl url = checkUrl(getDriverName("DRIVERNAME_MSSQL2005"), null,
JdbcUrl url = checkUrl(getDriverName("DRIVERNAME_MSSQL"), null,
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[<HOST>[\\<INSTANCE>][:<PORT>]][;databaseName=<DB>][;<ADDITIONAL>]",
supportedProps, requiredProps);
Expand Down Expand Up @@ -589,7 +588,7 @@ private JdbcUrl checkUrl(String name, String type, String className,
if (type == null) {
assertEquals(name, url.getDisplayName());
} else {
assertEquals(name + " (" + type + ")", url.getDisplayName());
assertEquals(name + " / " + type, url.getDisplayName());
}

assertEquals(className, url.getClassName());
Expand Down

0 comments on commit 2cea3bf

Please sign in to comment.