This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 74969
Collapse All | Expand All

(-)db/src/org/netbeans/api/db/explorer/JDBCDriverManager.java (-1 lines)
Lines 87-93 Link Here
87
        if (DEFAULT == null) {
87
        if (DEFAULT == null) {
88
            // init runtimes
88
            // init runtimes
89
            DatabaseRuntimeManager.getDefault().getRuntimes();
89
            DatabaseRuntimeManager.getDefault().getRuntimes();
90
            JDBCDriverConvertor.importOldDrivers();
91
            DEFAULT = new JDBCDriverManager();
90
            DEFAULT = new JDBCDriverManager();
92
        }
91
        }
93
        return DEFAULT;
92
        return DEFAULT;
(-)db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java (-3 lines)
Lines 72-80 Link Here
72
import org.netbeans.modules.db.explorer.dlg.ConnectPanel;
72
import org.netbeans.modules.db.explorer.dlg.ConnectPanel;
73
import org.netbeans.modules.db.explorer.dlg.ConnectProgressDialog;
73
import org.netbeans.modules.db.explorer.dlg.ConnectProgressDialog;
74
import org.openide.nodes.Node;
74
import org.openide.nodes.Node;
75
76
//import org.netbeans.modules.db.explorer.PointbasePlus;
77
78
import org.netbeans.modules.db.explorer.dlg.ConnectionDialog;
75
import org.netbeans.modules.db.explorer.dlg.ConnectionDialog;
79
import org.netbeans.modules.db.explorer.dlg.ConnectionDialogMediator;
76
import org.netbeans.modules.db.explorer.dlg.ConnectionDialogMediator;
80
import org.netbeans.modules.db.explorer.dlg.SchemaPanel;
77
import org.netbeans.modules.db.explorer.dlg.SchemaPanel;
(-)db/src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertor.java (-35 lines)
Lines 102-112 Link Here
102
    public static final String DRIVERS_PATH = "Databases/JDBCDrivers"; // NOI18N
102
    public static final String DRIVERS_PATH = "Databases/JDBCDrivers"; // NOI18N
103
    
103
    
104
    /**
104
    /**
105
     * The path where the drivers were registered in 4.1 and previous versions.
106
     */
107
    static final String OLD_DRIVERS_PATH = "Services/JDBCDrivers"; // NOI18N
108
109
    /**
110
     * The delay by which the write of the changes is postponed.
105
     * The delay by which the write of the changes is postponed.
111
     */
106
     */
112
    private static final int DELAY = 2000;
107
    private static final int DELAY = 2000;
Lines 263-298 Link Here
263
    }
258
    }
264
    
259
    
265
    /**
260
    /**
266
     * Moves the existing drivers from the old location (Services/JDBCDrivers) 
267
     * used in 4.1 and previous to the new one.
268
     */
269
    public static void importOldDrivers() {
270
        FileObject oldRoot = FileUtil.getConfigFile(JDBCDriverConvertor.OLD_DRIVERS_PATH);
271
        if (oldRoot == null) {
272
            return;
273
        }
274
        FileObject newRoot = FileUtil.getConfigFile(JDBCDriverConvertor.DRIVERS_PATH);
275
        FileObject[] children = oldRoot.getChildren();
276
        for (int i = 0; i < children.length; i++) {
277
            try {
278
                JDBCDriver drv = readDriverFromFile(children[i]);
279
                URL[] urls = drv.getURLs();
280
                for (int j = 0; j < urls.length; j++) {
281
                    urls[j] = encodeURL(urls[j]);
282
                }
283
                create(drv);
284
            } catch (Exception ex) {
285
                Exceptions.printStackTrace(ex);
286
            }
287
            try {
288
                children[i].delete();
289
            } catch (IOException e) {
290
                // what can we do?
291
            }
292
        }
293
    }
294
    
295
    /**
296
     * Encode an URL to be a valid URI. Be careful that this method will happily
261
     * Encode an URL to be a valid URI. Be careful that this method will happily
297
     * encode an already encoded URL! Use only on URLs which are not encoded.
262
     * encode an already encoded URL! Use only on URLs which are not encoded.
298
     */
263
     */
(-)db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java (-3 / +4 lines)
Lines 45-50 Link Here
45
package org.netbeans.api.db.explorer.support;
45
package org.netbeans.api.db.explorer.support;
46
46
47
import javax.swing.JComboBox;
47
import javax.swing.JComboBox;
48
import static junit.framework.Assert.assertEquals;
48
import org.netbeans.api.db.explorer.*;
49
import org.netbeans.api.db.explorer.*;
49
import org.netbeans.modules.db.test.TestBase;
50
import org.netbeans.modules.db.test.TestBase;
50
import org.netbeans.modules.db.test.Util;
51
import org.netbeans.modules.db.test.Util;
Lines 102-108 Link Here
102
        initConnections();
103
        initConnections();
103
        JComboBox combo = connect();
104
        JComboBox combo = connect();
104
105
105
        assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 3);
106
        assertEquals("Wrong number of items in the combobox", 3, combo.getItemCount());
106
107
107
        assertSame(dbconn2, combo.getItemAt(0));
108
        assertSame(dbconn2, combo.getItemAt(0));
108
        assertSame(dbconn1, combo.getItemAt(1));
109
        assertSame(dbconn1, combo.getItemAt(1));
Lines 110-122 Link Here
110
        DatabaseConnection dc = DatabaseConnection.create(Util.createDummyDriver(), "dc1", "user", "schema", "password", true);
111
        DatabaseConnection dc = DatabaseConnection.create(Util.createDummyDriver(), "dc1", "user", "schema", "password", true);
111
        ConnectionManager.getDefault().addConnection(dc);
112
        ConnectionManager.getDefault().addConnection(dc);
112
113
113
        assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 4);
114
        assertEquals("Wrong number of items in the combobox", 4, combo.getItemCount());
114
115
115
        assertSame(dc, combo.getItemAt(2));
116
        assertSame(dc, combo.getItemAt(2));
116
117
117
        ConnectionManager.getDefault().removeConnection(dc);
118
        ConnectionManager.getDefault().removeConnection(dc);
118
119
119
        assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 3);
120
        assertEquals("Wrong number of items in the combobox", 3, combo.getItemCount());
120
121
121
        assertSame(dbconn2, combo.getItemAt(0));
122
        assertSame(dbconn2, combo.getItemAt(0));
122
        assertSame(dbconn1, combo.getItemAt(1));
123
        assertSame(dbconn1, combo.getItemAt(1));
(-)db/test/unit/src/org/netbeans/modules/db/explorer/driver/JDBCDriverConvertorTest.java (-25 lines)
Lines 152-182 Link Here
152
        assertEquals(new URL("file:///test%20file"), JDBCDriverConvertor.encodeURL(new URL("file:///test file")));
152
        assertEquals(new URL("file:///test%20file"), JDBCDriverConvertor.encodeURL(new URL("file:///test file")));
153
    }
153
    }
154
    
154
    
155
    public void testImportOldDrivers() throws Exception {
156
        final String UNENCODED_URL = "file:///foo 1.jar";
157
        
158
        FileObject oldRoot = FileUtil.getConfigFile(JDBCDriverConvertor.OLD_DRIVERS_PATH);
159
        if (oldRoot == null) {
160
            oldRoot = FileUtil.createFolder(FileUtil.getConfigRoot(), JDBCDriverConvertor.OLD_DRIVERS_PATH);
161
        }
162
        URL[] urls = new URL[] { new URL(UNENCODED_URL) };
163
        createDriverFile10("testdriver.xml", oldRoot, urls);
164
        
165
        JDBCDriverConvertor.importOldDrivers();
166
        
167
        assertEquals(0, oldRoot.getChildren().length);
168
        
169
        FileObject newRoot = Util.getDriversFolder();
170
        assertEquals(1, newRoot.getChildren().length);
171
        
172
        Lookup.Result result = Lookups.forPath(newRoot.getPath()).lookup(new Lookup.Template(JDBCDriver.class));
173
        Collection instances = result.allInstances();
174
        JDBCDriver drv = (JDBCDriver)instances.iterator().next();
175
        assertEquals(JDBCDriverConvertor.encodeURL(new URL(UNENCODED_URL)), drv.getURLs()[0]);
176
        // assert the imported driver has a display name set
177
        assertEquals(drv.getName(), drv.getDisplayName());
178
    }
179
    
180
    private static FileObject createDriverFile10(String fileName, FileObject folder) throws Exception {
155
    private static FileObject createDriverFile10(String fileName, FileObject folder) throws Exception {
181
        URL[] urls = new URL[] {
156
        URL[] urls = new URL[] {
182
            new URL("file:///foo1.jar"),
157
            new URL("file:///foo1.jar"),

Return to bug 74969