# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/matthias/NetBeansProjects/main-golden # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: db/src/org/netbeans/api/db/explorer/JDBCDriver.java --- db/src/org/netbeans/api/db/explorer/JDBCDriver.java Base (BASE) +++ db/src/org/netbeans/api/db/explorer/JDBCDriver.java Locally Modified (Based On LOCAL) @@ -48,6 +48,7 @@ import java.sql.Driver; import java.sql.SQLException; import java.util.Arrays; +import java.util.Objects; import org.netbeans.modules.db.explorer.DbDriverManager; /** @@ -146,4 +147,33 @@ "',className='" + clazz + // NOI18N "',urls=" + Arrays.asList(urls) + "]"; // NOI18N } + + @Override + public int hashCode() { + return clazz.hashCode(); } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JDBCDriver other = (JDBCDriver) obj; + if (!Arrays.deepEquals(this.urls, other.urls)) { + return false; + } + if (!Objects.equals(this.clazz, other.clazz)) { + return false; + } + if (!Objects.equals(this.displayName, other.displayName)) { + return false; + } + if (!Objects.equals(this.name, other.name)) { + return false; + } + return true; + } +} Index: db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java --- db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java Base (BASE) +++ db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java Locally Modified (Based On LOCAL) @@ -132,7 +132,7 @@ if (drvClass == null) { throw new NullPointerException(); } - LinkedList res = new LinkedList(); + LinkedList res = new LinkedList<>(); JDBCDriver[] drvs = getDrivers(); for (int i = 0; i < drvs.length; i++) { if (drvClass.equals(drvs[i].getClassName())) { Index: db/src/org/netbeans/modules/db/util/Bundle.properties --- db/src/org/netbeans/modules/db/util/Bundle.properties Base (BASE) +++ db/src/org/netbeans/modules/db/util/Bundle.properties Locally Modified (Based On LOCAL) @@ -77,3 +77,5 @@ PropertyEditorPanel.propertyTable.columnModel.title0=Property PropertyEditorPanel.addRowButton.text=Add Property PropertyEditorPanel.removeRowButton.text=Remove Property + +JDBC_URL_DRIVER_NAME={0} on {1} \ No newline at end of file Index: db/src/org/netbeans/modules/db/util/DriverListUtil.java --- db/src/org/netbeans/modules/db/util/DriverListUtil.java Base (BASE) +++ db/src/org/netbeans/modules/db/util/DriverListUtil.java Locally Modified (Based On LOCAL) @@ -45,8 +45,7 @@ package org.netbeans.modules.db.util; import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -57,22 +56,22 @@ public class DriverListUtil { - private static List urls = new LinkedList(); + private static Set templateUrl = new HashSet<>(); private DriverListUtil() { } private static void add(JdbcUrl url) { - urls.add(url); + templateUrl.add(url); } private static void add(String name, String type, String driverClassName, String urlTemplate) { - urls.add(new JdbcUrl(name, name, driverClassName, type, urlTemplate)); + templateUrl.add(new JdbcUrl(name, name, driverClassName, type, urlTemplate)); } private static void add(String name, String type, String driverClassName, String urlTemplate, boolean parseUrl) { - urls.add(new JdbcUrl(name, name, driverClassName, type, urlTemplate, parseUrl)); + templateUrl.add(new JdbcUrl(name, name, driverClassName, type, urlTemplate, parseUrl)); } private static void add(String name, String driverClassName, String urlTemplate) { @@ -335,8 +334,8 @@ } public static Set getDrivers() { - TreeSet drivers = new TreeSet(); - for (JdbcUrl url : urls) { + TreeSet drivers = new TreeSet<>(); + for (JdbcUrl url : templateUrl) { // A set contains no duplicate elements, so if the same class name // is found twice, that's OK, because it just replaces the entry // that was already there @@ -346,52 +345,34 @@ } public static List getJdbcUrls(JDBCDriver driver) { - ArrayList driverUrls = new ArrayList(); - JdbcUrl newurl = null; + Set driverUrls = new HashSet<>(); - for (JdbcUrl url : urls) { + for (JdbcUrl url : templateUrl) { if (url.getClassName().equals(driver.getClassName())) { - if (url.getDriver() == null) { - url.setDriver(driver); - // Clear out any properties that may be set - url.clear(); - - driverUrls.add(url); - } else { - if (! isDriverEquals(driver, url.getDriver())) { - // We already have one driver registered for this class name. - // This is a new driver for the same driver class. That means - // it should be on the list with its own entry, but with the - // same URL tempate - newurl = new JdbcUrl(driver, url.getUrlTemplate(), url.isParseUrl()); + JdbcUrl newurl = new JdbcUrl(url, driver); + String connectionName = NbBundle.getMessage( + DriverListUtil.class, "JDBC_URL_DRIVER_NAME", + url.getDisplayName(), driver.getDisplayName()); + newurl.setDisplayName(connectionName); driverUrls.add(newurl); - } else { - driverUrls.add(url); } } - } - } - // Have to do this out of the loop or we get a ConcurrentModificationException - if (newurl != null) { - add(newurl); - } - if (driverUrls.isEmpty()) { driverUrls.add(new JdbcUrl(driver)); } - return driverUrls; + return new ArrayList<>(driverUrls); } - static List getJdbcUrls() { + static Set getJdbcUrls() { // For unit testing - return urls; + return templateUrl; } public static String getName(String driverClass) { // Find the first match - for ( JdbcUrl url : urls) { + for ( JdbcUrl url : templateUrl) { if (url.getClassName().equals(driverClass)) { return url.getName(); } @@ -402,40 +383,20 @@ public static String findFreeName(String name) { String ret; - List names = new ArrayList (); + List names = new ArrayList<>(); JDBCDriver[] drivers = JDBCDriverManager.getDefault().getDrivers(); - for (int i = 0; i < drivers.length; i++) + for (int i = 0; i < drivers.length; i++) { names.add(drivers[i].getDisplayName()); - - if (names.contains(name)) - for (int i = 1;;i++) { + } + if (names.contains(name)) { + for (int i = 1;; i++) { ret = name + " (" + i + ")"; // NOI18N - if (!names.contains(ret)) + if (!names.contains(ret)) { return ret; } - else + } + } else { return name; } - - private static boolean isDriverEquals(JDBCDriver driverOne, JDBCDriver driverTwo) { - // I didn't put this as a method on JDBCDriver because I don't want to change - // the behavior of equals() on a public class, and what we want for equals() - // may not be what others want. - if (driverOne == null && driverTwo == null) { - return true; } - - if (driverOne == null || driverTwo == null) { - return false; } - - if (driverOne == driverTwo) { - return true; - } - - return driverOne.getClassName().equals(driverTwo.getClassName()) && - driverOne.getDisplayName().equals(driverTwo.getDisplayName()) && - driverOne.getName().equals(driverTwo.getName()) && - Arrays.equals(driverOne.getURLs(), driverTwo.getURLs()); - } -} Index: db/src/org/netbeans/modules/db/util/JdbcUrl.java --- db/src/org/netbeans/modules/db/util/JdbcUrl.java Base (BASE) +++ db/src/org/netbeans/modules/db/util/JdbcUrl.java Locally Modified (Based On LOCAL) @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import org.netbeans.api.db.explorer.JDBCDriver; import org.openide.util.NbBundle; @@ -129,6 +130,12 @@ this.driver = driver; } + public JdbcUrl(JdbcUrl template, JDBCDriver driver) { + this(template.getName(), template.getDisplayName(), template.getClassName(), + template.getType(), template.getUrlTemplate(), template.isParseUrl()); + this.driver = driver; + } + public JdbcUrl(JDBCDriver driver) { this(driver, null, null); } @@ -163,6 +170,10 @@ return driver; } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + public String getDisplayName() { if (isEmpty(getType())) { return displayName; @@ -191,23 +202,45 @@ } @Override - public boolean equals(Object other) { - if (other == null || ! (other instanceof JdbcUrl)) { - return false; - } - - JdbcUrl otherUrl = (JdbcUrl)other; - - return otherUrl.getDisplayName().equals(this.getDisplayName()); - } - - @Override public int hashCode() { int hash = 3; - hash = 97 * hash + (this.getDisplayName() != null ? this.getDisplayName().hashCode() : 0); + hash = 23 * hash + Objects.hashCode(this.urlTemplate); return hash; } + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JdbcUrl other = (JdbcUrl) obj; + if (!Objects.equals(this.driver, other.driver)) { + return false; + } + if (this.parseUrl != other.parseUrl) { + return false; + } + if (!Objects.equals(this.name, other.name)) { + return false; + } + if (!Objects.equals(this.displayName, other.displayName)) { + return false; + } + if (!Objects.equals(this.className, other.className)) { + return false; + } + if (!Objects.equals(this.urlTemplate, other.urlTemplate)) { + return false; + } + if (!Objects.equals(this.type, other.type)) { + return false; + } + return true; + } + protected boolean isEmpty(String str) { return str == null || str.equals(""); }