diff -r 02c83941dec2 db/apichanges.xml --- a/db/apichanges.xml Fri Nov 19 18:31:47 2010 +0100 +++ b/db/apichanges.xml Mon Nov 22 11:09:08 2010 +0100 @@ -30,7 +30,7 @@ Contributor(s): The Original Software is NetBeans. The Initial Developer of the Original -Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun +Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. If you wish your version of this file to be governed by only the CDDL @@ -110,6 +110,21 @@ + Allow specify display name of the DatabaseConnection + + + + + + Allow to specify the display name of the connection as it shows + under the Databases node. Added new factory method to create + database connection with given display name. + + + + + + Add a DatabaseConnection.getJDBCDriver() method diff -r 02c83941dec2 db/nbproject/project.properties --- a/db/nbproject/project.properties Fri Nov 19 18:31:47 2010 +0100 +++ b/db/nbproject/project.properties Mon Nov 22 11:09:08 2010 +0100 @@ -45,7 +45,7 @@ javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=1.41.0 +spec.version.base=1.42.0 extra.module.files=modules/ext/ddl.jar diff -r 02c83941dec2 db/src/org/netbeans/api/db/explorer/DatabaseConnection.java --- a/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java Fri Nov 19 18:31:47 2010 +0100 +++ b/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java Mon Nov 22 11:09:08 2010 +0100 @@ -27,7 +27,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -87,6 +87,7 @@ static { DatabaseConnectionAccessor.DEFAULT = new DatabaseConnectionAccessor() { + @Override public DatabaseConnection createDatabaseConnection(org.netbeans.modules.db.explorer.DatabaseConnection conn) { return new DatabaseConnection(conn); } @@ -109,7 +110,8 @@ } /** - * Creates a new DatabaseConnection instance. + * Creates a new DatabaseConnection instance w/ a default display name based + * on connection URL and user * * @param driver the JDBC driver the new connection uses; cannot be null. * @param databaseURL the URL of the database to connect to; cannot be null. @@ -124,6 +126,27 @@ */ public static DatabaseConnection create(JDBCDriver driver, String databaseURL, String user, String schema, String password, boolean rememberPassword) { + return create(driver, databaseURL, user, schema, password, rememberPassword, null); + } + + /** + * Creates a new DatabaseConnection instance. + * + * @param driver the JDBC driver the new connection uses; cannot be null. + * @param databaseURL the URL of the database to connect to; cannot be null. + * @param user the username. + * @param schema the schema to use, or null for the default schema + * @param password the password. + * @param rememberPassword whether to remember the password for the current session. + * @param displayName the display name of the connection as it shows under the Databases node + * + * @return the new instance. + * + * @throws NullPointerException if driver or database are null. + */ + public static DatabaseConnection create(JDBCDriver driver, String databaseURL, + String user, String schema, String password, boolean rememberPassword, + String displayName) { if (driver == null || databaseURL == null) { throw new NullPointerException(); } @@ -135,7 +158,7 @@ conn.setSchema(schema); conn.setPassword(password); conn.setRememberPassword(rememberPassword); - + conn.setDisplayName(displayName); return conn.getDatabaseConnection(); } diff -r 02c83941dec2 db/test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java --- a/db/test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java Fri Nov 19 18:31:47 2010 +0100 +++ b/db/test/unit/src/org/netbeans/api/db/explorer/DatabaseConnectionTest.java Mon Nov 22 11:09:08 2010 +0100 @@ -27,7 +27,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2010 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -195,6 +195,42 @@ } } + /** + * Verifies that the {@link DatabaseConnection#create(org.netbeans.api.db.explorer.JDBCDriver, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, java.lang.String)} + * factory method creates a valid connection with the given display name + * + * @throws Exception + */ + public void testDatabaseConnectionCreatedWithDisplayName() throws Exception { + Util.clearConnections(); + Util.deleteDriverFiles(); + + JDBCDriver driver = Util.createDummyDriver(); + DatabaseConnection dbconn = DatabaseConnection.create(driver, "database", "user", "schema", "password", true, "displayName"); + + assertEquals("The connection was created with a display name different that the one provided", "displayName", dbconn.getDisplayName()); + + Util.clearConnections(); + + } + + /** + * Verifies that the {@link DatabaseConnection#create(org.netbeans.api.db.explorer.JDBCDriver, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)} + * creates some default display name that is not null + * @throws Exception + */ + public void testDatabaseConnectionCreatedWithDefaultDisplayName() throws Exception { + Util.clearConnections(); + Util.deleteDriverFiles(); + + JDBCDriver driver = Util.createDummyDriver(); + DatabaseConnection dbconn = DatabaseConnection.create(driver, "database", "user", "schema", "password", true); + + assertEquals("The connection was created with the default display name ", "database [user on schema]", dbconn.getDisplayName()); + + Util.clearConnections(); + } + private static boolean connectionIsValid(Connection conn) throws Exception { return org.netbeans.modules.db.explorer.DatabaseConnection.isVitalConnection(conn, null); }