Runtime Settings For Predefined Queries
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 com.sun.star.sdb.XQueriesSupplier returns query objects with the advanced settings above.
The Connection
gives you a com.sun.star.sdbcx.Container of com.sun.star.sdb.Query services. These Query
objects are different from QueryDefinitions
.
The com.sun.star.sdb.Query service inherits both the properties from com.sun.star.sdb.QueryDefinition service described previously, and the properties defined in the service com.sun.star.sdb.DataSettings. Use DataSettings
to customize the appearance of the query when used in the Apache OpenOffice API GUI or together with a com.sun.star.sdb.RowSet.
Properties of com.sun.star.sdb.DataSettings | |
---|---|
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 com.sun.star.awt.FontDescriptor. 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 com.sun.star.sdb.Query service offers a com.sun.star.sdbcx.XDataDescriptorFactory to create new query descriptors based on the current query information. Use this query descriptor to append new queries to the com.sun.star.sdbcx.Container using its com.sun.star.sdbcx.XAppend 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 com.sun.star.sdbcx.XRename interface is used to rename a query. It has one method:
void rename( [in] string newName)
The interface com.sun.star.sdbcx.XColumnsSupplier 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 com.sun.star.sdb.Column 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 com.sun.star.uno.Exception {
XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(
XNameAccess.class,_rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
// 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 com.sun.star.sdb.Query services
XNameAccess xQDefs = xQuerySup.getQueries();
// retrieve XColumnsSupplier of Query1
XColumnsSupplier xColsSup = (XColumnsSupplier) UnoRuntime.queryInterface(
XColumnsSupplier.class,xQDefs.getByName("Query1"));
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). |