org.apache.cocoon.acting.modular
Class DatabaseAddAction

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.modular.DatabaseAction
                          extended by org.apache.cocoon.acting.modular.DatabaseAddAction
All Implemented Interfaces:
Disposable, Component, Configurable, LogEnabled, Serviceable, ThreadSafe, Action

public class DatabaseAddAction
extends DatabaseAction

Adds record in a database. The action can update one or more tables, and can add more than one row to a table at a time. See DatabaseAction for details.

Version:
CVS $Id: DatabaseAddAction.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Christian Haul

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.cocoon.acting.modular.DatabaseAction
DatabaseAction.CacheHelper, DatabaseAction.Column, DatabaseAction.LookUpKey
 
Field Summary
 
Fields inherited from class org.apache.cocoon.acting.modular.DatabaseAction
cachedQueryData, dbselector, defaultModeNames, failOnEmpty, firstRow, pathSeparator
 
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
DatabaseAddAction()
           
 
Method Summary
protected  Object[][] getColumnValues(Configuration tableConf, DatabaseAction.CacheHelper queryData, Map objectModel)
          Fetch all values for all columns that are needed to do the database operation.
protected  DatabaseAction.CacheHelper getQuery(Configuration table, Map modeTypes, Map defaultModeNames)
          Get the String representation of the PreparedStatement.
protected  boolean honourAutoIncrement()
          determine whether autoincrement columns should be honoured by this operation.
protected  int processRow(Map objectModel, Connection conn, PreparedStatement statement, String outputMode, Configuration table, DatabaseAction.CacheHelper queryData, Object[][] columnValues, int rowIndex, Map results)
          set all necessary ?
protected  String selectMode(boolean isAutoIncrement, Map modes)
          determine which mode to use as default mode here: INSERT highly specific to operation INSERT / UPDATE / DELETE / SELECT
protected  int setKeyAuto(Configuration table, DatabaseAction.Column column, int currentIndex, int rowIndex, Connection conn, PreparedStatement statement, Map objectModel, String outputMode, Map results)
          Sets the key value on the prepared statement for an autoincrement type.
protected  void storeKeyValue(Configuration tableConf, DatabaseAction.Column key, int rowIndex, Connection conn, Statement statement, Map objectModel, String outputMode, Map results)
          Put key values into request attributes.
 
Methods inherited from class org.apache.cocoon.acting.modular.DatabaseAction
act, configure, dispose, fillModes, getColumnValue, getDataSource, getMode, getOutputName, getOutputName, isLargeObject, processTable, service, setColumn, setColumn, setOutput, setOutputAttribute
 
Methods inherited from class org.apache.cocoon.acting.AbstractComplementaryConfigurableAction
getConfiguration, getConfiguration, getConfiguration
 
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
 

Constructor Detail

DatabaseAddAction

public DatabaseAddAction()
Method Detail

processRow

protected int processRow(Map objectModel,
                         Connection conn,
                         PreparedStatement statement,
                         String outputMode,
                         Configuration table,
                         DatabaseAction.CacheHelper queryData,
                         Object[][] columnValues,
                         int rowIndex,
                         Map results)
                  throws SQLException,
                         ConfigurationException,
                         Exception
set all necessary ?s and execute the query

Specified by:
processRow in class DatabaseAction
Throws:
SQLException
ConfigurationException
Exception

setKeyAuto

protected int setKeyAuto(Configuration table,
                         DatabaseAction.Column column,
                         int currentIndex,
                         int rowIndex,
                         Connection conn,
                         PreparedStatement statement,
                         Map objectModel,
                         String outputMode,
                         Map results)
                  throws ConfigurationException,
                         SQLException,
                         Exception
Sets the key value on the prepared statement for an autoincrement type.

Parameters:
table - the table's configuration object
column - the key's configuration object
currentIndex - the position of the key column
rowIndex - the position in the current row set
conn - the database connection
statement - the insert statement
objectModel - the objectModel object
outputMode - name of the requested output module
results - sitemap result object
Returns:
the number of columns by which to increment the currentIndex
Throws:
ConfigurationException
SQLException
Exception

storeKeyValue

protected void storeKeyValue(Configuration tableConf,
                             DatabaseAction.Column key,
                             int rowIndex,
                             Connection conn,
                             Statement statement,
                             Map objectModel,
                             String outputMode,
                             Map results)
                      throws SQLException,
                             ConfigurationException,
                             ServiceException
Put key values into request attributes. Checks whether the value needs to be retrieved from the database module first.

Throws:
SQLException
ConfigurationException
ServiceException

selectMode

protected String selectMode(boolean isAutoIncrement,
                            Map modes)
determine which mode to use as default mode here: INSERT highly specific to operation INSERT / UPDATE / DELETE / SELECT

Specified by:
selectMode in class DatabaseAction

honourAutoIncrement

protected boolean honourAutoIncrement()
determine whether autoincrement columns should be honoured by this operation. This is usually snsible only for INSERTs.

Specified by:
honourAutoIncrement in class DatabaseAction

getColumnValues

protected Object[][] getColumnValues(Configuration tableConf,
                                     DatabaseAction.CacheHelper queryData,
                                     Map objectModel)
                              throws ConfigurationException,
                                     ServiceException
Fetch all values for all columns that are needed to do the database operation.

Throws:
ConfigurationException
ServiceException

getQuery

protected DatabaseAction.CacheHelper getQuery(Configuration table,
                                              Map modeTypes,
                                              Map defaultModeNames)
                                       throws ConfigurationException,
                                              ServiceException
Get the String representation of the PreparedStatement. This is mapped to the Configuration object itself, so if it doesn't exist, it will be created.

Specified by:
getQuery in class DatabaseAction
Parameters:
table - the table's configuration object
Returns:
the insert query as a string
Throws:
ConfigurationException
ServiceException


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