| java.lang.Object dinamica.AbstractModule dinamica.GenericTransaction
All known Subclasses: dinamica.security.GetMenu, dinamica.GetBlob, dinamica.security.Login, dinamica.security.GetProfile, dinamica.security.ChangePassword, dinamica.security.GetLoginHistory, dinamica.SortRS, dinamica.calendar.DefaultCalendar, dinamica.security.UpdateProfile, dinamica.SysInfo, dinamica.GenericChart, dinamica.SetLanguage, dinamica.RSSConsumer, dinamica.security.Logout, dinamica.MasterDetailReader, dinamica.ErrorHandler, dinamica.PagingControls, dinamica.AbstractValidator, dinamica.GenericTableManager,
GenericTransaction | public class GenericTransaction extends AbstractModule (Code) | | Base class to program business transaction services (read/write).
All transactions will subclass this class.
Creation date: 4/10/2003
Last Update: 4/10/2003
(c) 2003 Martin Cordova
This code is released under the LGPL license
author: Martin Cordova |
Method Summary | |
protected int | createRecordsets(Recordset inputParams) Create recordsets using config.xml parameters.
For recordsets created using SQL templates, all values
from the inputParams recordset will be auto-replaced into
the template. | protected Recordset | dbGet(String DataSourceName, String sql, int limit) | protected Recordset | dbGet(String DataSourceName, String sql) | public Recordset | getChartInfoRecordset() Create a recordset with all the fields
required to produce a chart with ChartOutput. | public HashMap<String, Recordset> | getData() | protected DataSource | getDataSource(String name) Return DataSource object using JNDI prefix
configured in web.xml context parameter. | protected DataSource | getDataSource() Return the default application DataSource object
as configured in web.xml context parameters. | protected String | getEnvEntry(String name) Returns an "env-entry" value stored in web.xml. | protected GenericTransaction | getObject(String className) Load the appropiate class and creates an object
that MUST subclass GenericTransaction. | public Recordset | getRecordset(String id) Returns a recordset published by this transaction
Parameters: id - ID or symbolic name which was used to publish therecordset - either by code or using the config.xml elements. | protected Recordset | getRsFromFlatFile(String path) Creates a recordset according to a structure defined in a
flat file. | protected String | getSQL(String sql, Recordset rs) Generate SQL command. | protected void | publish(String key, Recordset data) | public int | service(Recordset inputParams) Transaction service - this method must be redefined
by descendants of this class, include a super.service(inputParams)
as the first line of your service() method code to reuse base
functionality (auto-creation of recordsets based on recordset elements defined in config.xml).
In this method the business logic will be contained, and results will be represented
as recordsets that will be consumed by Output objects. |
createRecordsets | protected int createRecordsets(Recordset inputParams) throws Throwable(Code) | | Create recordsets using config.xml parameters.
For recordsets created using SQL templates, all values
from the inputParams recordset will be auto-replaced into
the template. This recordset is only created when using
a validator (validator.xml definition to auto-validate request parameters).
throws: Throwable - in case of invalid config.xml parameters or JDBC exceptions. |
dbGet | protected Recordset dbGet(String DataSourceName, String sql, int limit) throws Throwable(Code) | | Utility method to retrieve a recordset from a different data source
than the one used by the action
Parameters: DataSourceName - Data Source name like "jdbc/xxxx" Parameters: sql - SQL command that returns a result set Parameters: limit - The maximum number of rows to retrieve (0 = no limit) throws: Throwable - |
dbGet | protected Recordset dbGet(String DataSourceName, String sql) throws Throwable(Code) | | Utility method to retrieve a recordset from a different data source
than the one used by the action
Parameters: DataSourceName - Data Source name like "jdbc/xxxx" Parameters: sql - SQL command that returns a result set throws: Throwable - |
getChartInfoRecordset | public Recordset getChartInfoRecordset() throws Throwable(Code) | | Create a recordset with all the fields
required to produce a chart with ChartOutput. This recordset
will contain no records.
Recordset with the column structure required by the class ChartOutput throws: Throwable - |
getData | public HashMap<String, Recordset> getData()(Code) | | Retrieve internal HashMap containing all published Recordsets
in case some output module needs to serialize this object
or anything else
HashMap containing all published Recordsets |
getDataSource | protected DataSource getDataSource(String name) throws Throwable(Code) | | Return DataSource object using JNDI prefix
configured in web.xml context parameter. This is an
utility method to help simplify Transaction code. A DataSource
can be obtained with a single line of code:
javax.sql.DataSource ds = getDataSource("jdbc/customersDB");
setConnection(ds.getConnection);
....
Remember that when you use your own datasource, you
must close the connection in your Transaction code! consult
the reference guide ("Sample code" section) for more information.
Parameters: name - Name of the datasource (Example: jdbc/customersdb) DataSource object throws: Throwable - If DataSource cannot be obtained |
getDataSource | protected DataSource getDataSource() throws Throwable(Code) | | Return the default application DataSource object
as configured in web.xml context parameters. This is a
utility method to help simplify Transaction code. A DataSource
can be obtained with a single line of code:
javax.sql.DataSource ds = getDataSource();
setConnection(ds.getConnection());
....
Remember that when you use your own datasource, you
must close the connection in your Transaction code! please consult
the reference guide ("Sample code" section) for more information.
DataSource object throws: Throwable - If DataSource cannot be obtained |
getEnvEntry | protected String getEnvEntry(String name) throws Throwable(Code) | | Returns an "env-entry" value stored in web.xml.
Parameters: name - env-entry-name element |
getObject | protected GenericTransaction getObject(String className) throws Throwable(Code) | | Load the appropiate class and creates an object
that MUST subclass GenericTransaction. This method is
used by Transactions that delegate work on "subtransaction"
objects. All these classes subclass GenericTransaction to inherit all the
code supporting business logic programming. You may define your
own methods in those classes, they are intended to refactor
common business code that may be used by multiple Transactions.
Typically, you will use code like this:
MyOwnClass obj = (MyOwnClass)getObject("mypackage.MyOwnClass");
obj.myMethod();
An object created this way inherits all the power of
the GenericTransaction, including the availability of
security information (current user), access to the same
database connection as the caller, etc. Both objects participate
in the same JDBC Transaction if this feature was enabled in
the config.xml file.
Parameters: className - Name of the class to instantiate An object of class GenericTransaction throws: Throwable - |
getRecordset | public Recordset getRecordset(String id) throws Throwable(Code) | | Returns a recordset published by this transaction
Parameters: id - ID or symbolic name which was used to publish therecordset - either by code or using the config.xml elements. Recordset throws: Throwable - if ID oes not match any of the IDs of the published recordsets |
getRsFromFlatFile | protected Recordset getRsFromFlatFile(String path) throws Throwable(Code) | | Creates a recordset according to a structure defined in a
flat file. The 1st line defines the column types, the second line
defines the column names. From 3rd line begins data records. Columns
are separated by TAB, rows are separated by CR+NL.
Parameters: path - Path to flat file defining recordset structure and data. If path starts with "/..." it is interpreted as a location relativeto the context, otherwise it is assumed to be located in the Action's path. Recordset according to the flat file structure throws: Throwable - |
getSQL | protected String getSQL(String sql, Recordset rs) throws Throwable(Code) | | Generate SQL command. Encapsulates the use of the TemplateEngine
class, to make it easier for developers writing Transaction Modules
Parameters: sql - SQL Template Parameters: rs - Recordset with at least one record - there must bea current record SQL command with replaced values throws: Throwable - |
publish | protected void publish(String key, Recordset data) throws Throwable(Code) | | Publish recordset to be consumed by Output modules
Parameters: key - Recordset ID Parameters: data - Recordset object |
service | public int service(Recordset inputParams) throws Throwable(Code) | | Transaction service - this method must be redefined
by descendants of this class, include a super.service(inputParams)
as the first line of your service() method code to reuse base
functionality (auto-creation of recordsets based on recordset elements defined in config.xml).
In this method the business logic will be contained, and results will be represented
as recordsets that will be consumed by Output objects. Recordsets are published using
the method publish(id, rsObject). This class provides a method to retrieve
a recordset using its ID and throws an error if the recordset is not present in the HashMap.
If inputParams is not null then it is published with the id "_request".
Parameters: inputParams - Request parameters pre-validated and represented as a Recordset with one record.Recordset fields are set according to the data types defined in the validator.xml file. 0 if success - any other return values are user defined throws: Throwable - |
|
|