org.apache.cocoon.acting
Class AbstractDatabaseAction

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.acting.AbstractAction
          extended by org.apache.cocoon.acting.AbstractConfigurableAction
              extended by org.apache.cocoon.acting.ConfigurableServiceableAction
                  extended by org.apache.cocoon.acting.AbstractComplementaryConfigurableAction
                      extended by org.apache.cocoon.acting.AbstractDatabaseAction
All Implemented Interfaces:
Disposable, Component, Configurable, LogEnabled, Serviceable, Action
Direct Known Subclasses:
DatabaseAddAction, DatabaseAuthenticatorAction, DatabaseCookieAuthenticatorAction, DatabaseDeleteAction, DatabaseSelectAction, DatabaseUpdateAction, DbXMLAuthenticatorAction

public abstract class AbstractDatabaseAction
extends AbstractComplementaryConfigurableAction
implements Disposable

Set up environment for configurable form handling data. It is important to note that all DatabaseActions use a common configuration format. This group of actions are unique in that they employ a terciary mapping. There is the Form parameter, the database column, and the type. Each configuration file must use the same format in order to be effective. The name of the root configuration element is irrelevant.

   <root>
     <connection>personnel<connection>
     <table>
       <keys>
         <key param="id" dbcol="id" type="int"/>
       </keys>
       <values>
         <value param="name" dbcol="name" type="string"/>
         <value param="department" dbcol="department_id" type="int"/>
       </values>
     </table>
   </root>
 
The types recognized by this system are:
Type Description
ascii ASCII Input Stream, a CLOB input
big-decimal a java.math.BigDecimal value
binary Binary Input Stream, a BLOB input
byte a Byte
string a String
date a Date
double a Double
float a Float
int an Integer
long a Long
short a Short
time a Time
time-stamp a Timestamp
now a Timestamp with the current day/time--the form value is ignored.
image a binary image file, we cache the attribute information
image-width the width attribute of the cached file attribute. NOTE: param attribute must equal the param for image with a "-width" suffix.
image-height the width attribute of the cached file attribute NOTE: param attribute must equal the param for image with a "-height" suffix.
image-size the size attribute of the cached file attribute NOTE: param attribute must equal the param for image with a "-size" suffix.

Version:
$Id: AbstractDatabaseAction.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Berin Loritsch, Donald Ball

Field Summary
protected  ServiceSelector dbselector
           
protected  Map files
           
protected static Map typeConstants
           
 
Fields inherited from class org.apache.cocoon.acting.ConfigurableServiceableAction
manager
 
Fields inherited from class org.apache.cocoon.acting.AbstractConfigurableAction
settings
 
Fields inherited from class org.apache.cocoon.acting.AbstractAction
EMPTY_MAP
 
Fields inherited from interface org.apache.cocoon.acting.Action
ROLE
 
Constructor Summary
AbstractDatabaseAction()
           
 
Method Summary
protected  StringBuffer buildList(Configuration[] values, int begin)
          Build a separed list with the Values of a Configuration Array
protected  StringBuffer buildList(Configuration[] values, String separator)
          Build a separed list with the Values of a Configuration Array
 void dispose()
          dispose
protected  Object getColumn(ResultSet set, Request request, Configuration entry)
          Get the Statement column so that the results are mapped correctly.
protected  DataSourceComponent getDataSource(Configuration conf)
          Get the Datasource we need.
protected  Object getRequestAttribute(Request request, String key)
          Retreive a value from the request attributes.
protected  boolean isLargeObject(String type)
          Return whether a type is a Large Object (BLOB/CLOB).
 void service(ServiceManager manager)
          Compose the Actions so that we can select our databases.
protected  void setColumn(PreparedStatement statement, int position, Request request, Configuration entry)
          Set the Statement column so that the results are mapped correctly.
protected  void setColumn(PreparedStatement statement, int position, Request request, Configuration entry, String param)
          Set the Statement column so that the results are mapped correctly.
protected  void setColumn(PreparedStatement statement, int position, Request request, Configuration entry, String param, Object value)
          Set the Statement column so that the results are mapped correctly.
protected  void setColumn(PreparedStatement statement, int position, Request request, Configuration entry, String param, Object value, int rowIndex)
          Set the Statement column so that the results are mapped correctly.
protected  void setRequestAttribute(Request request, String key, Object value)
          Store a key/value pair in the request attributes.
 
Methods inherited from class org.apache.cocoon.acting.AbstractComplementaryConfigurableAction
getConfiguration, getConfiguration, getConfiguration
 
Methods inherited from class org.apache.cocoon.acting.AbstractConfigurableAction
configure
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.acting.Action
act
 

Field Detail

files

protected Map files

typeConstants

protected static final Map typeConstants

dbselector

protected ServiceSelector dbselector
Constructor Detail

AbstractDatabaseAction

public AbstractDatabaseAction()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Compose the Actions so that we can select our databases.

Specified by:
service in interface Serviceable
Overrides:
service in class ConfigurableServiceableAction
Throws:
ServiceException

getDataSource

protected final DataSourceComponent getDataSource(Configuration conf)
                                           throws ServiceException
Get the Datasource we need.

Throws:
ServiceException

isLargeObject

protected final boolean isLargeObject(String type)
Return whether a type is a Large Object (BLOB/CLOB).


getColumn

protected Object getColumn(ResultSet set,
                           Request request,
                           Configuration entry)
                    throws Exception
Get the Statement column so that the results are mapped correctly.

Throws:
Exception

setColumn

protected void setColumn(PreparedStatement statement,
                         int position,
                         Request request,
                         Configuration entry)
                  throws Exception
Set the Statement column so that the results are mapped correctly. The name of the parameter is retrieved from the configuration object.

Parameters:
statement - the prepared statement
position - the position of the column
request - the request
entry - the configuration object
Throws:
Exception

setColumn

protected void setColumn(PreparedStatement statement,
                         int position,
                         Request request,
                         Configuration entry,
                         String param)
                  throws Exception
Set the Statement column so that the results are mapped correctly. The value of the column is retrieved from the request object. If the named parameter exists in the request object's parameters, that value is used. Otherwise if the named parameter exists in the request object's attributes, that value is used. Otherwise the request object is retrieved using Request.get(attribute), which is documented to be the same as Request.getAttribute(attribute), so something weird must be going on.

Parameters:
statement - the prepared statement
position - the position of the column
request - the request
entry - the configuration object
param - the name of the request parameter
Throws:
Exception

setColumn

protected void setColumn(PreparedStatement statement,
                         int position,
                         Request request,
                         Configuration entry,
                         String param,
                         Object value)
                  throws Exception
Set the Statement column so that the results are mapped correctly.

Parameters:
statement - the prepared statement
position - the position of the column
request - the request
entry - the configuration object
param - the name of the request parameter
value - the value of the column
Throws:
Exception

setColumn

protected void setColumn(PreparedStatement statement,
                         int position,
                         Request request,
                         Configuration entry,
                         String param,
                         Object value,
                         int rowIndex)
                  throws Exception
Set the Statement column so that the results are mapped correctly.

Parameters:
statement - the prepared statement
position - the position of the column
request - the request
entry - the configuration object
param - the name of the request parameter
value - the value of the column
rowIndex - the index of the current row for manyrows inserts
Throws:
Exception

dispose

public void dispose()
dispose

Specified by:
dispose in interface Disposable

setRequestAttribute

protected void setRequestAttribute(Request request,
                                   String key,
                                   Object value)
Store a key/value pair in the request attributes. We prefix the key with the name of this class to prevent potential name collisions.


getRequestAttribute

protected Object getRequestAttribute(Request request,
                                     String key)
Retreive a value from the request attributes.


buildList

protected StringBuffer buildList(Configuration[] values,
                                 String separator)
                          throws ConfigurationException
Build a separed list with the Values of a Configuration Array

Parameters:
values - - build the list from
separator - - Put a separator between the values of the list
Returns:
- an StringBuffer with the builded List
Throws:
ConfigurationException

buildList

protected StringBuffer buildList(Configuration[] values,
                                 int begin)
                          throws ConfigurationException
Build a separed list with the Values of a Configuration Array

Parameters:
values - - build the list from
begin - - Initial index
Returns:
- an StringBuffer with the builded List
Throws:
ConfigurationException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.