public final class ConnectionManager extends Object
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.
DatabaseConnection
Constructor and Description |
---|
ConnectionManager() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static ConnectionManager getDefault()
public DatabaseConnection[] getConnections()
public DatabaseConnection getConnection(String name)
name
- the connection nameNullPointerException
- if the specified database name is null.public void addConnection(DatabaseConnection dbconn) throws DatabaseException
dbconn
- the connection to be added; must not be null.NullPointerException
- if dbconn is null.DatabaseException
- if an error occurs while adding the connection.public boolean connect(DatabaseConnection dbconn) throws DatabaseException
false
.
The connection is made synchronously in the calling thread, which must not be the AWT event dispatching thread.
dbconn
- the database connection to be connected.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.public void removeConnection(DatabaseConnection dbconn) throws DatabaseException
dbconn
- the connection to be removedDatabaseException
public void showAddConnectionDialog(JDBCDriver driver)
driver
- the JDBC driver; can be null.public void showAddConnectionDialog(JDBCDriver driver, String databaseUrl)
driver
- the JDBC driver; can be null.databaseUrl
- the database URL; can be null.public void showAddConnectionDialog(JDBCDriver driver, String databaseUrl, String user, String password)
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.public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver)
showAddConnectionDialog(JDBCDriver)
which returns
the newly created database connection, but must be called from the event dispatching
thread.driver
- the JDBC driver; can be null.IllegalStateException
- if the calling thread is not the event
dispatching thread.public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl)
showAddConnectionDialog(JDBCDriver, String)
which returns
the newly created database connection, but must be called from the event dispatching
thread.driver
- the JDBC driver; can be null.databaseUrl
- the database URL; can be null.IllegalStateException
- if the calling thread is not the event
dispatching thread.public DatabaseConnection showAddConnectionDialogFromEventThread(JDBCDriver driver, String databaseUrl, String user, String password)
showAddConnectionDialog(JDBCDriver, String, String, String)
which returns the newly created database connection, but must be called
from the event dispatching thread.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.IllegalStateException
- if the calling thread is not the event
dispatching thread.public void showConnectionDialog(DatabaseConnection dbconn)
dbconn
- the database connection to be connectedNullPointerException
- if the dbconn parameter is nullIllegalStateException
- if this connection is not added to the
ConnectionManager.public void disconnect(DatabaseConnection dbconn)
dbconn
- the database connection to be connectedNullPointerException
- if the dbconn parameter is nullIllegalStateException
- if this connection is not added to the
ConnectionManager.public void selectConnectionInExplorer(DatabaseConnection dbconn)
dbconn
- the connection to selectNullPointerException
- if the dbconn parameter is nullIllegalStateException
- if this connection is not added to the
ConnectionManager.public void refreshConnectionInExplorer(DatabaseConnection dbconn)
dbconn
- the connection to selectNullPointerException
- if the dbconn parameter is nullIllegalStateException
- if this connection is not added to the
ConnectionManager.public void addConnectionListener(ConnectionListener listener)
public void removeConnectionListener(ConnectionListener listener)
Built on June 4 2024. | Copyright © 2017-2024 Apache Software Foundation. All Rights Reserved.