| java.lang.Object sunlabs.brazil.template.Template sunlabs.brazil.template.SqlTemplate
SqlTemplate | public class SqlTemplate extends Template (Code) | | Sample Template class for running SQL queries via jdbc and
placing the results into the request properties for further processing.
Foreach session, a connection is made to an sql database via jdbc.
Session reconnection is attempted if the server connection breaks.
An SQL query is issued, with the results populating the request properties.
The following server properties are used:
- driver
- The name of the jdbc driver class for the desired database.
Currently, only one driver may be specified.
(e.g.
prefix.driver=org.gjt.mm.mysql.Driver ).
- url
- The jdbc url used to establish a connection with the
database. (e.g.
prefix.url=jdbc:mysql://host/db?user=xxx&password=yyy ).
- sqlPrefix
- The properties prefix for any additional parameters
that are required for this connection. For example:
prefix.sqlPrefix=params
params.user=my_name
params.password=xxx
All of the parameters are supplied to the jdbc connection
at connection time.
The driver and url parameters are required.
All of the code between <sql>...</sql>
is taken to be an SQL query, and sent to the appropriate database
for execution. The result of the query is placed into the request
properties for use by other templates, such as the
sunlabs.brazil.template.BSLTemplate BSLTemplate or
sunlabs.brazil.template.PropsTemplate PropsTemplate .
For a discussion of how the results map to properties,
SqlTemplate.tag_sql see below .
author: Stephen Uhler version: %V% SqlTemplate.java |
initialized | boolean initialized(Code) | | |
tag_sql | public void tag_sql(RewriteContext hr)(Code) | | Replace the SQL query with the appropriate request properties.
Look for the following parameters:
(NOTE - This interface is preliminary, and subject to change).
- debug
- Include diagnostics in html comments
- prefix
- prefix to prepend to all results.
Defaults to template prefix
- max
- The max # of rows returned (default=100)
- eval
- If present, do ${...} to entire query. (see
sunlabs.brazil.util.Format.getProperty getProperty ).
- index
- If present, use column 1 as part of the name.
Otherwise, an index name is invented.
For all queries, the following properties (with the prefix prepended)
are set:
- columns
- The number of columns returned
- row.count
- The number of rows returned
Foreach entry in the resultant table, its property is:
${prefix}.${table_name}.${columname}.${key} . If
the index parameter is set, the key is the value of
the first column returned. Otherwise the key is the row number,
and the additional property ${prefix}.rows contains a
list of all the row numbers returned.
|
|
|