Creating database queries

This topic describes how to extend IBM Director to create user-defined database queries. IBM Director enables you to create temporary queries and saved queries. Temporary queries are executed only once and their definitions are not saved in persistent storage. Saved queries are saved in persistent storage and are displayed as selectable queries on the IBM Director inventory query console. Saved queries can be either user-defined queries created using a user-defined query GUI or default queries created when the IBM Director Server is initialized.

Subtopics

Related topics

Related sample code

Creating and running a temporary query

The TWGDbCreateQueryCmd class is used to create and run temporary queries on the IBM Director database tables and on additional tables provided by IBM Director extensions. The TWGDbCreateQueryCmd class contains the parameters for a database command and is passed as an input parameter to an IPC command. The IPC command is sent to a database service node that processes the request. This create-and-run command code is used to specify that you want a temporary, rather than permanent, query.

Refer to IBM Director Interprocess Communication for information on programming service nodes and IPC commands.

Sample code on creating and running a temporary query is provided in the SampleCreateRunQuery.java file.

Creating a default query

If you are defining new database tables, you can create default queries for those tables. Default queries are displayed automatically in the Available Queries window of the IBM Director Inventory Query Browser. You define default queries in the InitClassInstances() method of your extension's TWGExtension subclass.

A sample default query is provided in the SampleInventoryCollectorExtension.java file.

Creating your own query interface

Use the following Java classes to retrieve information about tables and queries and to manipulate queries. These classes can help you create your own query GUI. Each of these classes contains the parameters for a database command, and each is passed as an input parameter to an IPC command. The IPC command is sent to a database query service node that processes the request.

TWGDbGetTablesCmd
Requests meta information about the tables in the IBM Director database. For example, you might need the token names of all of the columns in the table.
TWGDbGetQueriesCmd
Requests meta information about a single database-saved query or all saved queries.
TWGDbCreateQueryCmd
Creates a user-defined saved query or a temporary query.
TWGDbRunQueryCmd
Runs an existing saved query.
TWGDbChangeQueryCmd
Modifies the parameters of an existing database query.
TWGDbCopyQueryCmd
Makes a copy of a default query. The new query is a user-defined query.
TWGDbDelQueryCmd
Deletes a default or user-defined query; however, it is recommended that query GUIs prohibit users from deleting default queries.