Data Sources in

From Apache OpenOffice Wiki
Jump to: navigation, search
  • Data Sources in API


In the graphical user interface (GUI), define Open Office database files using the database application Base, and register them in the Tools - Options - Database - Databasesdialog in order to access them in the database browser. A data source has five main aspects. It contains the following:

  • The general information necessary to connect to a data source.
  • Settings to control the presentation of tables, and queries.
  • SQL query definitions.
  • Database forms.
  • Database reports.

From the API perspective, these functions are mirrored in the service. The database context is a container for data sources. It is a singleton, that is, it may exist only once in a running API instance and can be accessed by creating it at the global service manager of the office.

The Dialog "Database Registration"

The database context is the entry point for applications that need to connect to a data source already defined in the API. Additionally, it is used to create new data sources and add them to API. The following figure shows the relationship between the database context, the data sources and the connection over a data source.

The database context is used to get a data source that provides a through its interface.

Existing data sources are obtained from the database context at its interfaces and Their methods getByName() and createEnumeration() deliver the services defined in the GUI.

Since 2.0, getByName() can also be used to obtain data sources that are not registered. You only need to pass a URL pointing to a valid database file, which is then automatically loaded by the context.

The code below shows how to print all available registered data sources:

  // prints all data sources
  public static void printDataSources(XMultiServiceFactory _rMSF) throws {
      // retrieve the DatabaseContext and get its interface
      XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(
          XNameAccess.class, _rMSF.createInstance(""));
      // print all DataSource names
      String aNames [] = xNameAccess.getElementNames();
      for (int i=0;i<aNames.length;++i)
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages