org.netbeans.modules.db/1 1.44.1 30

org.netbeans.api.db.explorer
Class ConnectionManager

java.lang.Object
  extended by org.netbeans.api.db.explorer.ConnectionManager

public final class ConnectionManager
extends Object

Provides access to the list of connections in the Database Explorer.

The list of connections can be retrieved using the getConnections() method. A connection can be also retrieved by name using the getConnection(java.lang.String) method.

New connections can be added to the Connection Manager using the addConnection(org.netbeans.api.db.explorer.DatabaseConnection) method (new connections can be created using the DatabaseConnection.create(org.netbeans.api.db.explorer.JDBCDriver, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) method. It is also possible to display the New Database Connection dialog to let the user create a new database connection using the showAddConnectionDialog(org.netbeans.api.db.explorer.JDBCDriver). Connections can be realized using the showConnectionDialog(org.netbeans.api.db.explorer.DatabaseConnection) method.

Clients can be informed of changes to the ConnectionManager by registering a ConnectionListener using the addConnectionListener(org.netbeans.api.db.explorer.ConnectionListener) method.

See Also:
DatabaseConnection

Constructor Summary
ConnectionManager()
           
 
Method Summary
 void addConnection(DatabaseConnection dbconn)
          Adds a new connection to Database Explorer.
 void addConnectionListener(ConnectionListener listener)
          Registers a ConnectionListener.
 boolean connect(DatabaseConnection dbconn)
          Connects this connection to the database without opening any dialog.
 void disconnect(DatabaseConnection dbconn)
          Disconnects this connection from the database.
 DatabaseConnection getConnection(String name)
          Returns the connection with the specified name.
 DatabaseConnection[] getConnections()
          Returns the list of connections in the Database Explorer.
static ConnectionManager getDefault()
          Gets the ConnectionManager singleton instance.
 void refreshConnectionInExplorer(DatabaseConnection dbconn)
          Refresh the node corresponding to the specified connection in the Runtime tab.
 void removeConnection(DatabaseConnection dbconn)
          Remove an existing connection from the Database Explorer.
 void removeConnectionListener(ConnectionListener listener)
          Unregisters the specified connection listener.
 void selectConnectionInExplorer(DatabaseConnection dbconn)
          Selects the node corresponding to the specified connection in the Runtime tab.
 void showAddConnectionDialog(JDBCDriver driver)
          Shows the dialog for adding a new connection.
 void showAddConnectionDialog(JDBCDriver driver, String databaseUrl)
          Shows the dialog for adding a new connection with the specified database URL.
 void showAddConnectionDialog(JDBCDriver driver, String databaseUrl, String user, String password)
          Shows the dialog for adding a new connection with the specified database URL, user and password The specified driver be filled as the single element of the Driver combo box of the New Database Connection dialog box.
 DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver)
          The counterpart of showAddConnectionDialog(JDBCDriver) which returns the newly created database connection, but must be called from the event dispatching thread.
 DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl)
          The counterpart of showAddConnectionDialog(JDBCDriver, String) which returns the newly created database connection, but must be called from the event dispatching thread.
 DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl, String user, String password)
          The counterpart of showAddConnectionDialog(JDBCDriver, String, String, String) which returns the newly created database connection, but must be called from the event dispatching thread.
 void showConnectionDialog(DatabaseConnection dbconn)
          Shows the Connect dialog for the specified connection if not all data needed to connect, such as the user name or password, are known), or displays a modal progress dialog and attempts to connect to the database immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
Method Detail

getDefault

public static ConnectionManager getDefault()
Gets the ConnectionManager singleton instance.


getConnections

public DatabaseConnection[] getConnections()
Returns the list of connections in the Database Explorer.

Returns:
a non-null array of connections.

getConnection

public DatabaseConnection getConnection(String name)
Returns the connection with the specified name.

Parameters:
name - the connection name
Throws:
NullPointerException - if the specified database name is null.

addConnection

public void addConnection(DatabaseConnection dbconn)
                   throws DatabaseException
Adds a new connection to Database Explorer. This method does not display any UI and does not try to connect to the respective database.

Parameters:
dbconn - the connection to be added; must not be null.
Throws:
NullPointerException - if dbconn is null.
DatabaseException - if an error occurs while adding the connection.

connect

public boolean connect(DatabaseConnection dbconn)
                throws DatabaseException
Connects this connection to the database without opening any dialog. If not all the necessary parameters, such as the user name or password, are set, the method will silently return false.

The connection is made synchronously in the calling thread, which must not be the AWT event dispatching thread.

Parameters:
dbconn - the database connection to be connected.
Returns:
false if not all parameters necessary to connect are available.
Throws:
NullPointerException - if the dbconn parameter is null.
DatabaseException - if an error occurs while connecting.
IllegalStateException - if this connection is not added to the ConnectionManager or the calling thread is the AWT event dispatching thread.
Since:
1.26

removeConnection

public void removeConnection(DatabaseConnection dbconn)
                      throws DatabaseException
Remove an existing connection from the Database Explorer. This method unregisters the connection from the the explorer so it will no longer appear as a connection in the UI. This method also closes the underlying JDBC connection if it is open.

Parameters:
dbconn - the connection to be removed
Throws:
DatabaseException
Since:
1.25

showAddConnectionDialog

public void showAddConnectionDialog(JDBCDriver driver)
Shows the dialog for adding a new connection. The specified driver will be selected by default in the New Database Connection dialog.

Parameters:
driver - the JDBC driver; can be null.

showAddConnectionDialog

public void showAddConnectionDialog(JDBCDriver driver,
                                    String databaseUrl)
Shows the dialog for adding a new connection with the specified database URL. The specified driver be filled as the single element of the Driver combo box of the New Database Connection dialog box. The database URL will be filled in the Database URL field in the New Database Connection dialog box.

Parameters:
driver - the JDBC driver; can be null.
databaseUrl - the database URL; can be null.

showAddConnectionDialog

public void showAddConnectionDialog(JDBCDriver driver,
                                    String databaseUrl,
                                    String user,
                                    String password)
Shows the dialog for adding a new connection with the specified database URL, user and password The specified driver be filled as the single element of the Driver combo box of the New Database Connection dialog box. The database URL will be filled in the Database URL field in the New Database Connection dialog box. The user and password will be filled in the User Name and Password fields in the New Database Connection dialog box.

Parameters:
driver - the JDBC driver; can be null.
databaseUrl - the database URL; can be null.
user - the database user; can be null.
password - user's password; can be null.
Since:
1.19

showAddConnectionDialogFromEventThread

public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver)
The counterpart of showAddConnectionDialog(JDBCDriver) which returns the newly created database connection, but must be called from the event dispatching thread.

Parameters:
driver - the JDBC driver; can be null.
Returns:
the new database connection or null if no database connection was created (e.g. the user pressed Cancel).
Throws:
IllegalStateException - if the calling thread is not the event dispatching thread.
Since:
1.19

showAddConnectionDialogFromEventThread

public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver,
                                                                 String databaseUrl)
The counterpart of showAddConnectionDialog(JDBCDriver, String) which returns the newly created database connection, but must be called from the event dispatching thread.

Parameters:
driver - the JDBC driver; can be null.
databaseUrl - the database URL; can be null.
Returns:
the new database connection or null if no database connection was created (e.g. the user pressed Cancel).
Throws:
IllegalStateException - if the calling thread is not the event dispatching thread.
Since:
1.19

showAddConnectionDialogFromEventThread

public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver,
                                                                 String databaseUrl,
                                                                 String user,
                                                                 String password)
The counterpart of showAddConnectionDialog(JDBCDriver, String, String, String) which returns the newly created database connection, but must be called from the event dispatching thread.

Parameters:
driver - the JDBC driver; can be null.
databaseUrl - the database URL; can be null.
user - the database user; can be null.
password - user's password; can be null.
Returns:
the new database connection or null if no database connection was created (e.g. the user pressed Cancel).
Throws:
IllegalStateException - if the calling thread is not the event dispatching thread.
Since:
1.19

showConnectionDialog

public void showConnectionDialog(DatabaseConnection dbconn)
Shows the Connect dialog for the specified connection if not all data needed to connect, such as the user name or password, are known), or displays a modal progress dialog and attempts to connect to the database immediately.

Parameters:
dbconn - the database connection to be connected
Throws:
NullPointerException - if the dbconn parameter is null
IllegalStateException - if this connection is not added to the ConnectionManager.

disconnect

public void disconnect(DatabaseConnection dbconn)
Disconnects this connection from the database. Does not do anything if not connected.

Parameters:
dbconn - the database connection to be connected
Throws:
NullPointerException - if the dbconn parameter is null
IllegalStateException - if this connection is not added to the ConnectionManager.

selectConnectionInExplorer

public void selectConnectionInExplorer(DatabaseConnection dbconn)
Selects the node corresponding to the specified connection in the Runtime tab.

Parameters:
dbconn - the connection to select
Throws:
NullPointerException - if the dbconn parameter is null
IllegalStateException - if this connection is not added to the ConnectionManager.

refreshConnectionInExplorer

public void refreshConnectionInExplorer(DatabaseConnection dbconn)
Refresh the node corresponding to the specified connection in the Runtime tab.

Parameters:
dbconn - the connection to select
Throws:
NullPointerException - if the dbconn parameter is null
IllegalStateException - if this connection is not added to the ConnectionManager.
Since:
1.40

addConnectionListener

public void addConnectionListener(ConnectionListener listener)
Registers a ConnectionListener.


removeConnectionListener

public void removeConnectionListener(ConnectionListener listener)
Unregisters the specified connection listener.


org.netbeans.modules.db/1 1.44.1 30

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.