Runtime Settings For Predefined Queries

From Apache OpenOffice Wiki
Jump to: navigation, search

The queries in the user interface have a number of advanced settings concerning the formatting and filtering of the query and its columns. For the API, these settings are available as long as the data source is connected with the underlying database. The section Connecting Through a DataSource discusses how to get a connection from a data source. When the connection is made, its interface returns query objects with the advanced settings above.

Connection, QueryComposer And Query in the sdb Module

The Connection gives you a of services. These Query objects are different from QueryDefinitions.

The service inherits both the properties from service described previously, and the properties defined in the service Use DataSettings to customize the appearance of the query when used in the Apache OpenOffice API GUI or together with a

Properties of
Filter string - An additional filter for the data object, WHERE clause syntax.
ApplyFilter boolean - Indicates if the filter should be applied, default is FALSE.
Order string - Is an additional sort order definition.
FontDescriptor struct Specifies the font attributes for displayed data.
RowHeight long - Specifies the height of a data row.
TextColor long - Specifies the text color for displayed text in 0xAARRGGBB notation

In addition to these properties, the service offers a to create new query descriptors based on the current query information. Use this query descriptor to append new queries to the using its interface. This is an alternative to the connection-independent method to create new queries as discussed above. The section The Descriptor Pattern explains how to use descriptors to append new elements to database objects.

The interface is used to rename a query. It has one method:

  void rename( [in] string newName)

The interface grants access to the column settings of the query through its single method getColumns():

  com::sun::star::container::XNameAccess getColumns()

The columns returned by getColumns() are services that provide column information and the ability to improve the appearance of columns. This service is explained in the section Tables and Columns.

The following code sample connects to Bibliography, and prints the column names and types of the previously defined query Query1.

  public static void printQueryColumnNames(XMultiServiceFactory _rMSF) throws {
      XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(
      // we use Bibliography
      XDataSource xDS = (XDataSource)UnoRuntime.queryInterface(
          XDataSource.class, xNameAccess.getByName("Bibliography"));
      // simple way to connect
      XConnection con = xDS.getConnection("", "");
      // we need the XQueriesSupplier interface of the connection
      XQueriesSupplier xQuerySup = (XQueriesSupplier)UnoRuntime.queryInterface(
          XQueriesSupplier.class, con);
      // get container with services
      XNameAccess xQDefs = xQuerySup.getQueries();
      // retrieve XColumnsSupplier of Query1
      XColumnsSupplier xColsSup = (XColumnsSupplier) UnoRuntime.queryInterface(
      XNameAccess xCols = xColsSup.getColumns();
      // Access column property TypeName
      String aNames [] = xCols.getElementNames();
      for (int i=0;i<aNames.length;++i) {
          Object col = xCols.getByName(aNames[i]);
          XPropertySet xColumnProps = (XPropertySet)UnoRuntime.queryInterface(
              XPropertySet.class, col);
          System.out.println(aNames[i] + " " + xColumnProps.getPropertyValue("TypeName"));
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages