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

(-)a/db/apichanges.xml (+15 lines)
Lines 107-112 Link Here
107
    <changes>
107
    <changes>
108
        <change>
108
        <change>
109
            <api name="database_explorer_api"/>
109
            <api name="database_explorer_api"/>
110
            <summary>Add a DatabaseConnection.getJDBCDriver() method</summary>
111
            <version major="1" minor="32"/>
112
            <date day="6" month="5" year="2009"/>
113
            <author login="jrechtacek"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                Currently there is no easy way to get the JDBCDriver instance that a
117
                DatabaseConnection will use / used to connect to a database. A
118
                <code>DatabaseConnection.getJDBCDriver()</code> method should be added.
119
            </description>
120
            <class package="org.netbeans.api.db.explorer" name="DatabaseConnection"/>
121
            <issue number="90210"/>
122
        </change>
123
        <change>
124
            <api name="database_explorer_api"/>
110
            <summary>Add ability to ensure a JDBC connection is valid</summary>
125
            <summary>Add ability to ensure a JDBC connection is valid</summary>
111
            <version major="1" minor="30"/>
126
            <version major="1" minor="30"/>
112
            <date day="27" month="8" year="2008"/>
127
            <date day="27" month="8" year="2008"/>
(-)a/db/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
javadoc.arch=${basedir}/arch.xml
42
javadoc.arch=${basedir}/arch.xml
43
javadoc.apichanges=${basedir}/apichanges.xml
43
javadoc.apichanges=${basedir}/apichanges.xml
44
44
45
spec.version.base=1.31.0
45
spec.version.base=1.32.0
46
46
47
extra.module.files=modules/ext/ddl.jar
47
extra.module.files=modules/ext/ddl.jar
48
48
(-)a/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java (-2 / +13 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 146-151 Link Here
146
    }
146
    }
147
147
148
    /**
148
    /**
149
     * Returns the JDBC driver instance that this connection uses.
150
     *
151
     * @since 1.32
152
     * @return the JDBC driver or null if no driver registred
153
     */
154
    public JDBCDriver getJDBCDriver() {
155
        return delegate.findJDBCDriver ();
156
    }
157
158
    /**
149
     * Returns this connection's database URL.
159
     * Returns this connection's database URL.
150
     *
160
     *
151
     * @return the connection's database URL
161
     * @return the connection's database URL
Lines 275-280 Link Here
275
    /**
285
    /**
276
     * Returns a string representation of the database connection.
286
     * Returns a string representation of the database connection.
277
     */
287
     */
288
    @Override
278
    public String toString() {
289
    public String toString() {
279
        return "DatabaseConnection[name='" + getName() + "']"; // NOI18N
290
        return "DatabaseConnection[name='" + getName() + "']"; // NOI18N
280
    }
291
    }
(-)a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java (-12 / +24 lines)
Lines 69-74 Link Here
69
import org.netbeans.lib.ddl.DDLException;
69
import org.netbeans.lib.ddl.DDLException;
70
import org.netbeans.api.db.explorer.DatabaseException;
70
import org.netbeans.api.db.explorer.DatabaseException;
71
import org.netbeans.api.db.explorer.JDBCDriver;
71
import org.netbeans.api.db.explorer.JDBCDriver;
72
import org.netbeans.api.db.explorer.JDBCDriverListener;
72
import org.netbeans.api.db.explorer.JDBCDriverManager;
73
import org.netbeans.api.db.explorer.JDBCDriverManager;
73
74
74
import org.netbeans.modules.db.ExceptionListener;
75
import org.netbeans.modules.db.ExceptionListener;
Lines 169-174 Link Here
169
    public static final String DRIVER_CLASS_NET = "org.apache.derby.jdbc.ClientDriver"; // NOI18N
170
    public static final String DRIVER_CLASS_NET = "org.apache.derby.jdbc.ClientDriver"; // NOI18N
170
    public static final int DERBY_UNICODE_ERROR_CODE = 20000;
171
    public static final int DERBY_UNICODE_ERROR_CODE = 20000;
171
    private OpenConnectionInterface openConnection = null;
172
    private OpenConnectionInterface openConnection = null;
173
    private JDBCDriver jdbcdrv = null;
174
    private JDBCDriverListener jdbcL = new JDBCDriverListener () {
175
        public void driversChanged () {
176
            jdbcdrv = null;
177
        }
178
    };
179
172
180
173
    static private final Lookup.Result<OpenConnectionInterface> openConnectionLookupResult;
181
    static private final Lookup.Result<OpenConnectionInterface> openConnectionLookupResult;
174
    static private Collection openConnectionServices = null;
182
    static private Collection openConnectionServices = null;
Lines 187-192 Link Here
187
    public DatabaseConnection() {
195
    public DatabaseConnection() {
188
        dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this);
196
        dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this);
189
        propertySupport = new PropertyChangeSupport(this);
197
        propertySupport = new PropertyChangeSupport(this);
198
        JDBCDriverManager.getDefault().addDriverListener (jdbcL);
190
    }
199
    }
191
200
192
    /** Advanced constructor
201
    /** Advanced constructor
Lines 220-238 Link Here
220
    }
229
    }
221
230
222
    public JDBCDriver findJDBCDriver() {
231
    public JDBCDriver findJDBCDriver() {
223
        JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDrivers(drv);
232
        if (jdbcdrv == null) {
224
        if (drvs.length <= 0) {
233
            JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDrivers(drv);
225
            return null;
234
            if (drvs.length <= 0) {
235
                return null;
236
            }
237
238
            JDBCDriver useDriver = drvs[0];
239
            for (int i = 0; i < drvs.length; i++) {
240
                if (drvs[i].getName().equals(getDriverName())) {
241
                    useDriver = drvs[i];
242
                    break;
243
                }
244
            }
245
            return useDriver;
226
        }
246
        }
227
247
        return jdbcdrv;
228
        JDBCDriver useDriver = drvs[0];
229
        for (int i = 0; i < drvs.length; i++) {
230
            if (drvs[i].getName().equals(getDriverName())) {
231
                useDriver = drvs[i];
232
                break;
233
            }
234
        }
235
        return useDriver;
236
    }
248
    }
237
249
238
    public Connection getJDBCConnection(boolean test) {
250
    public Connection getJDBCConnection(boolean test) {
(-)a/db/test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java (-7 / +32 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 43-52 Link Here
43
43
44
import java.sql.Connection;
44
import java.sql.Connection;
45
import java.sql.SQLException;
45
import java.sql.SQLException;
46
import java.util.logging.Level;
47
import org.netbeans.modules.db.test.Util;
46
import org.netbeans.modules.db.test.Util;
48
import org.netbeans.modules.db.test.DBTestBase;
47
import org.netbeans.modules.db.test.DBTestBase;
49
import org.openide.util.NbBundle;
50
48
51
/**
49
/**
52
 *
50
 *
Lines 72-85 Link Here
72
70
73
        DatabaseConnection dbconn = DatabaseConnection.create(driver, "database", "user", "schema", "password", true);
71
        DatabaseConnection dbconn = DatabaseConnection.create(driver, "database", "user", "schema", "password", true);
74
        ConnectionManager.getDefault().addConnection(dbconn);
72
        ConnectionManager.getDefault().addConnection(dbconn);
75
        
73
76
        assertTrue(ConnectionManager.getDefault().getConnections().length > 0);
74
        assertTrue(ConnectionManager.getDefault().getConnections().length > 0);
77
        
75
78
        Util.clearConnections();
76
        Util.clearConnections();
79
        
77
80
        assertTrue(ConnectionManager.getDefault().getConnections().length == 0);
78
        assertTrue(ConnectionManager.getDefault().getConnections().length == 0);
81
    }
79
    }
82
80
81
    public void testGetJDDCDriver() throws Exception{
82
        Util.clearConnections();
83
        Util.deleteDriverFiles();
84
85
        JDBCDriver driver = Util.createDummyDriver();
86
        assertEquals(1, JDBCDriverManager.getDefault().getDrivers().length);
87
88
        DatabaseConnection dbconn = DatabaseConnection.create(driver, "database", "user", "schema", "password", true);
89
        assertEquals ("Returns the correct driver", driver, dbconn.getJDBCDriver ());
90
    }
91
92
    public void testGetJDDCDriverWhenAddOtherDriver() throws Exception{
93
        Util.clearConnections();
94
        Util.deleteDriverFiles();
95
96
        JDBCDriver driver1 = Util.createDummyDriver();
97
        assertEquals(1, JDBCDriverManager.getDefault().getDrivers().length);
98
        DatabaseConnection dbconn1 = DatabaseConnection.create(driver1, "database", "user", "schema", "password", true);
99
        assertEquals ("Returns the correct driver", driver1, dbconn1.getJDBCDriver ());
100
101
        JDBCDriver driver2 = Util.createDummyDriverWithOtherJar ();
102
        assertEquals(2, JDBCDriverManager.getDefault().getDrivers().length);
103
        DatabaseConnection dbconn2 = DatabaseConnection.create(driver2, "database", "user", "schema", "password", true);
104
        assertEquals ("Returns the correct driver", driver1, dbconn1.getJDBCDriver ());
105
        assertEquals ("Returns the correct driver", driver2, dbconn2.getJDBCDriver ());
106
    }
107
83
    public void testSameDatabaseConnectionReturned() throws Exception {
108
    public void testSameDatabaseConnectionReturned() throws Exception {
84
        Util.clearConnections();
109
        Util.clearConnections();
85
        Util.deleteDriverFiles();
110
        Util.deleteDriverFiles();
(-)a/db/test/unit/src/org/netbeans/modules/db/test/Util.java (-6 / +14 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 82-97 Link Here
82
    }
82
    }
83
    
83
    
84
    public static JDBCDriver createDummyDriver() throws Exception {
84
    public static JDBCDriver createDummyDriver() throws Exception {
85
        JDBCDriver[] drivers = 
85
        JDBCDriver[] drivers =
86
                JDBCDriverManager.getDefault().getDrivers("org.bar.barDriver");
86
                JDBCDriverManager.getDefault().getDrivers("org.bar.barDriver");
87
        if ( drivers.length > 0 ) {
87
        if ( drivers.length > 0 ) {
88
            return drivers[0];
88
            return drivers[0];
89
        }
89
        }
90
        
90
91
        JDBCDriver driver = JDBCDriver.create("bar_driver", "Bar Driver", 
91
        JDBCDriver driver = JDBCDriver.create("bar_driver", "Bar Driver",
92
                "org.bar.BarDriver", new URL[]{ new URL("file://foo/path/foo.jar")});
92
                "org.bar.BarDriver", new URL[]{ new URL("file://foo/path/foo.jar")});
93
        JDBCDriverManager.getDefault().addDriver(driver);
93
        JDBCDriverManager.getDefault().addDriver(driver);
94
                
94
95
        return driver;
96
    }
97
98
    public static JDBCDriver createDummyDriverWithOtherJar() throws Exception {
99
        JDBCDriver driver = JDBCDriver.create("bar_driver", "Bar Driver",
100
                "org.bar.BarDriver2", new URL[]{ new URL("file://foo2/path/foo2.jar")});
101
        JDBCDriverManager.getDefault().addDriver(driver);
102
95
        return driver;
103
        return driver;
96
    }
104
    }
97
}
105
}

Return to bug 90210