Connecting Apama Applications to External Components > Using Standard Adapters > Using the Apama Database Connector > The ADBC Event Application Programming Interface > Named queries > Creating named queries
Creating named queries
Each named query in the ADBC-queryTemplates-SQL.xml file is defined in an XML <query> element. Each <query> element has the following attributes:
*name — The name of the query.
*description — A short description of the query.
*implementationFunction — The substitution function that the adapter uses to process the named query. The substitution function allows you to specify tokens that are replaced by parameters with matching names.
*inputString — A string that contains the substitution tokens you want to replace with values specified as parameters.
A <query> element can also have one or more optional <parameter> child elements. Each <parameter> element has the following attributes:
*description — A short description of the parameter.
*name — The name of the parameter.
*type — The data type of the parameter.
*default — The default value of the parameter.
As an example, the following XML code in the ADBC-queryTemplates-SQL.xml file defines the pre-built findEarliest named query. The query returns the row with the earliest time.

<query
name="findEarliest"
description="Get the row with the earliest time."
implementationFunction="substitution"
inputString="select * from ${TABLE_NAME} order by ${TIME_COLUMN_NAME}
asc limit 1">
<parameter
description="Name of a table to query"
name="TABLE_NAME"
type="String"
default=""/>
<parameter
description="Name of the time column"
name="TIME_COLUMN_NAME"
type="String"
default="time"/>
</query>
To create a named query:
1. In the Project Explorer, expand the project’s Adapters node and open the adapter folder.
2. Double-click the instance configuration file to open it in the adapter editor.
3. In the adapter editor, select the Advanced tab.
4. Click the ADBC-queryTemplates-SQL.xml file to open it.
5. Select the Design tab.
6. On the Design tab, right-click the namedQuery element and select Add Child > New Element .
7. In the New Element dialog, type query, then click OK. A new query row is added to the list.
8. For each of the four attributes (name, description, implementationFunction, inputString):
a. Right-click the query element you added in Step 4, and select Add Attribute > New Attribute .
b. In the New Attribute dialog, provide a Name and a Value for the attribute.
9. If you want the query to use input parameters, for each parameter:
a. a. Right-click the query element and select Add Child > New Element .
b. b. In the New Element dialog, type parameter, then click OK.
c. c. Create the following attributes for each parameter:
*description
*name
*type
*default
10. Save the project's version of the query template file.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.