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 134309
Collapse All | Expand All

(-)a/db/apichanges.xml (+15 lines)
Lines 105-110 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
        <change>
109
            <api name="database_explorer_api"/>
110
            <summary>Add ability to get the underlying JDBC Driver instance for a JDBCDriver</summary>
111
            <version major="1" minor="28"/>
112
            <date day="27" month="6" year="2008"/>
113
            <author login="davidvc"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                This change makes it possible to get the underlying Driver class.  Without
117
                this, the only way you can obtain the driver is to create your own classloader that
118
                has the driver classpath URLs in its search list and then load the driver.
119
                This makes things much easier.
120
            </description>
121
            <issue number="134309"/>
122
        </change>
108
        <change>
123
        <change>
109
            <api name="database_explorer_api"/>
124
            <api name="database_explorer_api"/>
110
            <summary>Add ability to show the Add JDBC Driver dialog synchronously</summary>
125
            <summary>Add ability to show the Add JDBC Driver dialog synchronously</summary>
(-)a/db/arch.xml (+8 lines)
Lines 206-211 Link Here
206
    This file should be registered in the <code>Databases/JDBCDrivers</code> folder of the module layer.
206
    This file should be registered in the <code>Databases/JDBCDrivers</code> folder of the module layer.
207
    To addres a bundled JAR inside the IDE the nbinst protocol can be used in the URLs: 
207
    To addres a bundled JAR inside the IDE the nbinst protocol can be used in the URLs: 
208
    <code>nbinst:/modules/ext/bundled-driver.jar</code>.
208
    <code>nbinst:/modules/ext/bundled-driver.jar</code>.
209
   </p>
210
  </usecase>
211
  <usecase id="get-jdbc-driver" name="Get the underlying JDBC Driver instance for a JDBCDriver">
212
   <p>
213
      You can use the <a href="@TOP@org/netbeans/api/db/explorer/JDBCDriver.html#getDriver()">JDBCDriver.getDriver()</a>
214
      method to obtain a reference to the underlying JDBC Driver instance.  This is useful if you want to use the registered
215
      drivers but create your own JDBC connections independent of the Database Explorer.
216
209
   </p>
217
   </p>
210
  </usecase>
218
  </usecase>
211
  <usecase id="retrieve-drivers" name="Retrieving the list of JDBC ../db.drivers">
219
  <usecase id="retrieve-drivers" name="Retrieving the list of JDBC ../db.drivers">
(-)a/db/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.db/1
2
OpenIDE-Module: org.netbeans.modules.db/1
3
OpenIDE-Module-Install: org/netbeans/modules/db/DatabaseModule.class
3
OpenIDE-Module-Install: org/netbeans/modules/db/DatabaseModule.class
4
OpenIDE-Module-Implementation-Version: 27
4
OpenIDE-Module-Implementation-Version: 28
5
OpenIDE-Module-Layer: org/netbeans/modules/db/resources/mf-layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/db/resources/mf-layer.xml
6
OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help
6
OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help
7
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/db/resources/Bundle.properties
7
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/db/resources/Bundle.properties
(-)a/db/src/org/netbeans/api/db/explorer/JDBCDriver.java (+22 lines)
Lines 42-48 Link Here
42
package org.netbeans.api.db.explorer;
42
package org.netbeans.api.db.explorer;
43
43
44
import java.net.URL;
44
import java.net.URL;
45
import java.sql.Driver;
46
import java.sql.SQLException;
45
import java.util.Arrays;
47
import java.util.Arrays;
48
import org.netbeans.modules.db.explorer.DbDriverManager;
46
49
47
/**
50
/**
48
 * Encapsulates a JDBC driver.
51
 * Encapsulates a JDBC driver.
Lines 114-119 Link Here
114
    public String getName() {
117
    public String getName() {
115
        return name;
118
        return name;
116
    }
119
    }
120
121
    /**
122
     * Get a reference to the underlying java.sql.Driver for this JDBCDriver.
123
     * This can be useful if you want to use the registered drivers to manage
124
     * your own JDBC connections independent of the Database Explorer
125
     *
126
     * @return an instance of the java.sql.Driver for this JDBCDriver
127
     *
128
     * @throws DatabaseException if there was an error trying to get the driver instance
129
     * 
130
     * @since 1.28
131
     */
132
    public Driver getDriver() throws DatabaseException {
133
        try {
134
            return DbDriverManager.getDefault().getDriver(this);
135
        } catch (SQLException sqle) {
136
            throw new DatabaseException(sqle);
137
        }
138
    }
117
    
139
    
118
    public String toString() {
140
    public String toString() {
119
        return "JDBCDriver[name='" + name + // NOI18N
141
        return "JDBCDriver[name='" + name + // NOI18N
(-)a/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java (-7 / +18 lines)
Lines 213-218 Link Here
213
        }
213
        }
214
        return d;
214
        return d;
215
    }
215
    }
216
217
    /**
218
     * Get the driver for a JDBCDriver.  It only tries to load it using Class.forName() -
219
     * there is no URL to work with
220
     */
221
    public Driver getDriver(JDBCDriver jdbcDriver) throws SQLException {
222
        ClassLoader l = getClassLoader(jdbcDriver);
223
        try {
224
            return (Driver)Class.forName(jdbcDriver.getClassName(), true, l).newInstance();
225
        } catch (Exception e) {
226
            SQLException sqlex = createDriverNotFoundException();
227
            sqlex.initCause(e);
228
            throw sqlex;
229
        }
230
    }
216
    
231
    
217
    /**
232
    /**
218
     * Gets a driver, but can skip DriverManager and doesn't throw SQLException if a driver can't be found.
233
     * Gets a driver, but can skip DriverManager and doesn't throw SQLException if a driver can't be found.
Lines 236-248 Link Here
236
        
251
        
237
        // didn't find it, try to load it from jdbcDriver, if any
252
        // didn't find it, try to load it from jdbcDriver, if any
238
        if (jdbcDriver != null) {
253
        if (jdbcDriver != null) {
239
            ClassLoader l = getClassLoader(jdbcDriver);
254
            Driver d = getDriver(jdbcDriver);
240
            try {
255
            if (d != null) {
241
                return (Driver)Class.forName(jdbcDriver.getClassName(), true, l).newInstance();
256
                return d;
242
            } catch (Exception e) {
243
                SQLException sqlex = createDriverNotFoundException();
244
                sqlex.initCause(e);
245
                throw sqlex;
246
            }
257
            }
247
        }
258
        }
248
        
259
        
(-)a/db/test/unit/src/org/netbeans/api/db/explorer/JDBCDriverManagerTest.java (-4 / +11 lines)
Lines 41-59 Link Here
41
41
42
package org.netbeans.api.db.explorer;
42
package org.netbeans.api.db.explorer;
43
43
44
import java.lang.ref.WeakReference;
45
import java.net.URL;
44
import java.net.URL;
45
import java.sql.Driver;
46
import org.netbeans.modules.db.explorer.driver.JDBCDriverConvertor;
46
import org.netbeans.modules.db.explorer.driver.JDBCDriverConvertor;
47
import org.netbeans.modules.db.test.TestBase;
48
import org.netbeans.modules.db.test.Util;
47
import org.netbeans.modules.db.test.Util;
48
import org.netbeans.modules.db.util.DBTestBase;
49
import org.openide.loaders.DataObject;
49
import org.openide.loaders.DataObject;
50
50
51
/**
51
/**
52
 *
52
 *
53
 * @author Andrei Badea
53
 * @author Andrei Badea
54
 */
54
 */
55
public class JDBCDriverManagerTest extends TestBase {
55
public class JDBCDriverManagerTest extends DBTestBase {
56
57
    public JDBCDriverManagerTest(String testName) {
56
    public JDBCDriverManagerTest(String testName) {
58
        super(testName);
57
        super(testName);
59
    }
58
    }
Lines 98-101 Link Here
98
        assertSame(driver, JDBCDriverManager.getDefault().getDrivers("org.bar.BarDriver")[0]);
97
        assertSame(driver, JDBCDriverManager.getDefault().getDrivers("org.bar.BarDriver")[0]);
99
         */
98
         */
100
    }
99
    }
100
101
    public void testGetDriver() throws Exception {
102
        JDBCDriver jdbcDriver = getJDBCDriver();
103
        Driver driver = jdbcDriver.getDriver();
104
105
        assertNotNull(driver);
106
107
    }
101
}
108
}
(-)a/db/test/unit/src/org/netbeans/modules/db/util/DBTestBase.java (-3 / +13 lines)
Lines 130-143 Link Here
130
        super(name);
130
        super(name);
131
    }
131
    }
132
132
133
    protected static JDBCDriver getJDBCDriver() throws Exception{
134
        if (jdbcDriver == null) {
135
            jdbcDriver = JDBCDriver.create("derbydriver", "derbydriver", driverClass, new URL[] {driverJarUrl});
136
            assertNotNull(jdbcDriver);
137
            JDBCDriverManager.getDefault().addDriver(jdbcDriver);
138
        }
139
140
        return jdbcDriver;
141
142
    }
143
133
    /**
144
    /**
134
     * Get the DatabaseConnection for the configured Java DB database.  This
145
     * Get the DatabaseConnection for the configured Java DB database.  This
135
     * method will create and register the connection the first time it is called
146
     * method will create and register the connection the first time it is called
136
     */
147
     */
137
    protected static DatabaseConnection getDatabaseConnection() throws Exception {
148
    protected static DatabaseConnection getDatabaseConnection() throws Exception {
138
        if (dbConnection == null) {
149
        if (dbConnection == null) {
139
            JDBCDriver driver = JDBCDriver.create("derbydriver", "derbydriver", driverClass, new URL[] {driverJarUrl});
150
            JDBCDriver driver = getJDBCDriver();
140
            JDBCDriverManager.getDefault().addDriver(driver);
141
151
142
            dbConnection = DatabaseConnection.create(driver, dbUrl, username, "APP", password, false);
152
            dbConnection = DatabaseConnection.create(driver, dbUrl, username, "APP", password, false);
143
            ConnectionManager.getDefault().addConnection(dbConnection);
153
            ConnectionManager.getDefault().addConnection(dbConnection);
Lines 208-214 Link Here
208
        conn = DriverManager.getConnection(dbUrl, username, password);
218
        conn = DriverManager.getConnection(dbUrl, username, password);
209
        return conn;
219
        return conn;
210
    }
220
    }
211
221
    
212
    protected void createSchema() throws Exception {
222
    protected void createSchema() throws Exception {
213
        dropSchema();
223
        dropSchema();
214
        conn.createStatement().executeUpdate("CREATE SCHEMA " + SCHEMA);
224
        conn.createStatement().executeUpdate("CREATE SCHEMA " + SCHEMA);

Return to bug 134309