|
org.netbeans.modules.db/0 1.20.0 4 | |||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Database Explorer | |
---|---|
org.netbeans.api.db.explorer | |
org.netbeans.api.db.explorer.support | |
org.netbeans.spi.db.explorer |
The Database Explorer module provides the DatabaseExplorerAPI which allows access to the database connections and drivers defined in the Database Explorer. It allows a client to retrieve the connection list and their properties and to create new connections. The Database Explorer also manages a list of JDBC drivers used to connect to databases. The API provides access to these drivers and allows to create new and remove existing drivers.
The DatabaseExplorerLayerAPI allows for the declarative registration of database connections and JDBC drivers in the module layer. Database runtimes (which are representations of an instance of a database server) can also be registered in the layer.
Loaders-text-dbschema-Actions
allows extending .dbschema
files with own actions by registering them in the
Loaders/text/x-dbschema/Actions
folder. Note that this folder is actually provided by the
org-netbeans-modules-dbschema.jar
module.
Loaders-text-sql-Actions
allows extending .sql
files with own actions by registering them in the
Loaders/text/x-sql/Actions
folder. Note that this folder is actually provided by the
org-netbeans-modules-db-core.jar
module.
This change adds a showAddConnectionDialog
which opens the
New Connection Dialog while pre-filling a specified database user and password.
It also adds showAddConnectionDialogFromEventThread
methods
which are counterparts to the showAddConnectionDialog
methods,
with the difference that they return the newly added database connection,
but must be called from the event dispatching thread.
This change adds the DatabaseExplorerUIs.connect()
method, which populates a JComboBox
with the list of connections
from a ConnectionManager
.
First initial release of the Database Explorer API.
An external module can register JDBC drivers. A typical example is a module which provides integration with a database server. In this case the module contains the JDBC driver for that database server and uses the Database Explorer API to add it do the Database Explorer.
Another client of this API could be a module providing integration with a J2EE application server. Sometimes a J2EE application server bundles a database server for improving the out-of-the-box experience. When the server is registered in the IDE the JDBC drivers for the bundled database server are added to the Database Explorer.
The drivers are registered by making calls on JDBCDriverManager or by registering an XML file which describes the driver in the module layer. The XML file is described by the JDBC Driver DTD. An example of a registration file describing the JDBC driver for PostgreSQL follows:
<?xml version='1.0'?> <!DOCTYPE driver PUBLIC '-//NetBeans//DTD JDBC Driver 1.0//EN' 'http://www.netbeans.org/dtds/jdbc-driver-1_0.dtd'> <driver> <name value='postgresql-7'/> <display-name value='PostgreSQL (v7.0 and later)'/> <class value='org.postgresql.Driver'/> <urls> <url value='file:/folder1/folder2/drivers/pg74.1jdbc3.jar'/> </urls> </driver>
This file should be registered in the Databases/JDBCDrivers
folder of the module layer.
To addres a bundled JAR inside the IDE the nbinst protocol can be used in the URLs:
nbinst:/modules/ext/bundled-driver.jar
.
When creating a new connection the JDBC driver which it should use can be specified. A list of all the registered JDBC drivers can be retrieved using JDBCDriverManager.getDrivers().
An external module can register new database runtimes. A database runtime
is an abstraction of a database server instance
(usually bundled with the IDE, an integration module or with a J2EE server). It allows a database
server instance to be started and stopped when a connection to this
instance is made in the IDE. Database runtimes are represented by the
DatabaseRuntime
SPI interface and are registered in the Databases/Runtimes
of the module layer.
A module can create new database connections (for example to a bundled database). New connections can be added by calling DatabaseConnection.create() to create a new DatabaseConnection instance and then ConnectionManager.addConnection() to add the connection to the Database Explorer.
New connections can also be added by registering them in the module layer. The format of the registration file is described by the Database Connection DTD. An example of a registration file describing a connection to a PostgreSQL database follows:
<?xml version='1.0'?> <!DOCTYPE connection PUBLIC '-//NetBeans//DTD Database Connection 1.0//EN' 'http://www.netbeans.org/dtds/connection-1_0.dtd'> <connection> <driver-class value='org.postgresql.Driver'/> <driver-name value='postgres-7'/> <database-url value='jdbc:postgresql:test'/> <schema value='public'/> <user value='test'/> </connection>
This file should be registered in the Databases/Connections
folder of the module layer.
Sometimes the list of connections needs to be displayed somewhere else in the IDE than the Runtime tab. A typical example is the SQL Editor, which allows the user to select the database connection which the SQL statement will be executed against in a combo box in the editor toolbar. The list of connections can be obtained by calling ConnectionManager.getConnections(), which returns an array of DatabaseConnection instances.
The client usually needs to show the display name of the connection. The display name can be retrieved using the DatabaseConnection.getDisplayName() method.
Sometimes a client needs to retrieve the connection properties, such as the driver class.
An example could be a module for a J2EE server creating a connection pool. The properties can
be retrieved using the getDriverClass()
, getDatabaseURL()
,
getSchema()
, getUser()
and getPassword()
methods of the
DatabaseConnection
class.
Usually when displaying a list of connections (usually in a combo box), the last item is "New Connection", which displays the standard New Database Connection dialog of the Database Explorer. This can be achieved by calling one of the ConnectionManager.showAddConnectionDialog() methods.
A component which provides database functionality (such as the SQL Editor)
will need to connect to a database. This can be achieved using the
DatabaseConnection.showConnectionDialog()
method and the java.sql.Connection
instance can be retrieved using the
getJDBCConnection()
method.
A component which provides database functionality (such as the SQL Editor
or a module providing support for data sources) will need to let the user
select the a database connection, usually through a combo box.
This can be achieved using the
DatabaseExplorerUIs.connect()
method. The JComboBox
passed to the method will be filled with the list of connections as returned by
ConnectionManager.getConnections(), followed by a separator
and a New Database Connection item which will display the dialog for adding a new database connection when selected.
|
|
The sources for the module are in NetBeans CVS in db directory.
Nothing.
Read more about the implementation in the answers to architecture questions.
|
org.netbeans.modules.db/0 1.20.0 4 | |||||||||
PREV NEXT | FRAMES NO FRAMES |