Database support technical overview

Directory structure

db - Database Explorer

 core - Database Core (non-visual part of the SQL editor)
 dbapi - Friend Database APIs (listening to db metadata, SQL keywords)
 derby - Java DB Database Support
 model - Database Schema
 sqleditor - SQL Editor (visual part of the SQL editor)

Also there are javahelp, directories belonging to db (libsrc, src, test) and module web pages (www).


Database Core (db/core)

  • SQLDataLoader. DataLoader and DataObject for SQL files, with support for "console" SQL files stored in the userdir. SQLCloneableEditor (the non-visual part of the SQL editor).
  • SQLExecuteHelper: support for executing SQL scripts.
  • SQLResultPanel: ui for displaying the result of a SELECT statement.
  • SQLExecuteCookie, SQLExecution: friend API for communication between the DB Core and the SQL Editor modules. SQLExecution is used by the SQL editor to provide actions for executing the contents of the editor.

Database APIs (db/dbapi)

  • MetaDataListener: originally needed for the code completion for db metadata in the JPA support to refresh the metadata cache when invoking the Refresh action in the DB Explorer. Now unused, since the code completion is disabled and needs to be reimplemented to use Retouche.
  • SQLKeywords: provides a list of SQL-99 keywords to other modules in the db area and to the JPA verification.

Java DB Database Support (db/derby)

  • RegisterDerby: implements DatabaseRuntime, which allows the DB Explorer to start a database when making the first connection to it.
  • CreateDatabaseAction, StartAction, StopAction, DerbySettingsAction: actions in the Tools - Java DB Database menu.
  • JDKDerbyHelper: helper class for locating the installation path of Java DB bundled with the JDK.
  • DerbyDatabases: API allowing other modules to create the sample Java DB databases and new databases.
  • DerbySupport: API allowing the GlassFish plugin to set the location of the Java DB database to the one it bundles and to ensure that Java DB is started when deploying an application.

Note how "Derby" is used in the code, but Java DB is used in places visible to the user. This is by intention.

Database Schema (db/model)

  • org.netbeans.modules.dbschema: defines the basic dbschema API -- classes representing database objects such as tables, columns or keys (TableElement, ColumnElement, KeyElement, etc.). Each of these classes delegates to an Impl class, which allows for various implementations. By default there is a in-memory implementation called Memory.
  • org.netbeans.modules.dbschema.jdbcimpl: the so-called JDBC implementation, which implements the Impl classes to delegate to DatabaseMetaData.
  • org.netbeans.modules.dbschema.jdbcimpl.wizard: wizard for capturing a dbschema. Allows to select a connection and choose the tables and views to be captured. Also support for recapturing a dbschema.
  • org.netbeans.modules.dbschema.nodes: contains the nodes representing a dbschema in the UI.

SQL Editor (db/sqleditor)

  • SQLSyntax: despite the misleading name, contains the lexical analyzer for SQL.
  • SQLExecutionBaseAction: the base action that all actions in the SQL editor toolbar subclass. The action is dependent on a SQLExecution instance found in the lookup of the SQL editor TopComponent.

Database Explorer (db)

There are two source roots: src and libsrc.

libsrc contains the so-called DDL library, which has two functions. First, it serves as a thin wrapper over DatabaseMetaData (see DriverSpecification). Second, it can execute DDL statements for various databases (see DatabaseSpecification and DDLCommand and its subclasses). The DDL statements (the so-called "database specifications") are stored in file dbspec.plist.

src contains the visual parts of the Database Explorer: the drivers and connection management, the logical view (the driver, connection and database object nodes) and the actions. It delegates to the DDL library for executing DDL statements.

The logical view is composed of two packages (o.n.m.db.explorer.infos and o.n.m.db.explorer.nodes) which form two parallel trees of objects which delegate to each other (each node has an "info" and each info knows its node). This scheme tries to separate the logic (info classes) from the UI (nodes), but it sometimes doesn't really succeed. For example the code which registers a new connection (currently partially in ConnectUsingDriverAction and partially in ConnectionNodeInfo) should be entirely separated from infos and nodes (and probably actions too).

src also contains a public API providing other modules with access to the drivers and connections registered in the DB Explorer.

Important classes and packages:

  • org.netbeans.api.db.explorer: the public API for working with drivers and connections. It allows other modules to retrieve the registered drivers and connections and to register new ones. The most important classes are DatabaseConnection, ConnectionManager, JDBCDriver and JDBCDriverManager. This API is has been under development since its introduction in 5.0 and should be made stable in 6.0. There is also a support subpackage which makes it easier to display database connections in the UI.
  • org.netbeans.modules.db.explorer: contains miscellaneous implementation classes. Most important are DatabaseConnection (the implementation class to which org.netbeans.api.db.explorer.DatabaseConnection delegates to), DatabaseConnectionConvertor (loads/stored a DatabaseConnection from/to an XML file), DbDriverManager (manages URLClassLoaders which JDBC drivers are loaded from).
  • org.netbeans.modules.db.explorer.actions, infos, nodes: the logical view
  • org.netbeans.modules.db.runtime: contains DatabaseRuntimeManager, which manages instances of DatabaseRuntime's -- interfaces which allow the DB Explorer to start a database when making the first connection to it.
  • org.netbeans.modules.db.spi.sql.editor, visualsqleditor: contain SPIs which allow the DB Explorer to open a SQL and a visual SQL editor, respectively.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo