org.apache.cocoon.components.modules.database
Class ManualAutoIncrementModule

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.cocoon.components.modules.database.AbstractAutoIncrementModule
              |
              +--org.apache.cocoon.components.modules.database.ManualAutoIncrementModule
All Implemented Interfaces:
AutoIncrementModule, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.thread.ThreadSafe

public class ManualAutoIncrementModule
extends AbstractAutoIncrementModule
implements org.apache.avalon.framework.thread.ThreadSafe

Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns. Here: manual mode The new value is determined by doing a "select max(column)+1 from table" query. With transactions and correct isolation levels, this should to the trick almost everywhere. Note however, that the above query does not prevent a parallel transaction to try to insert a row with the same ID since it requires only shared locks. C.f. "Phantom Problem"

Version:
CVS $Id: ManualAutoIncrementModule.java,v 1.2 2002/05/28 13:41:28 haul Exp $
Author:
Christian Haul

Fields inherited from class org.apache.cocoon.components.modules.database.AbstractAutoIncrementModule
settings
 
Fields inherited from interface org.apache.cocoon.components.modules.database.AutoIncrementModule
ROLE
 
Constructor Summary
ManualAutoIncrementModule()
           
 
Method Summary
 java.lang.Object getPostValue(org.apache.avalon.framework.configuration.Configuration tableConf, org.apache.avalon.framework.configuration.Configuration columnConf, org.apache.avalon.framework.configuration.Configuration modenConf, java.sql.Connection conn, java.sql.Statement stmt, java.util.Map objectModel)
          Return key attribute value of last inserted row.
 java.lang.Object getPreValue(org.apache.avalon.framework.configuration.Configuration tableConf, org.apache.avalon.framework.configuration.Configuration columnConf, org.apache.avalon.framework.configuration.Configuration modeConf, java.sql.Connection conn, java.util.Map objectModel)
          Provide the value for the key attribute column.
protected  java.lang.String getSelectQuery(java.lang.String tableName, org.apache.avalon.framework.configuration.Configuration entry)
           
 java.lang.String getSubquery(org.apache.avalon.framework.configuration.Configuration tableConf, org.apache.avalon.framework.configuration.Configuration columnConf, org.apache.avalon.framework.configuration.Configuration modeConf)
          Provide subquery string for the key attribute column.
 boolean includeAsValue()
          Boolean whether the key attribute needs to be included in the insert query as an attribute value (no subquery).
 boolean includeInQuery()
          Boolean whether the key attribute column needs to be included in the insert query.
protected  void setSelectQuery(java.lang.String tableName, org.apache.avalon.framework.configuration.Configuration entry)
          Set the String representation of the MaxID lookup statement.
 
Methods inherited from class org.apache.cocoon.components.modules.database.AbstractAutoIncrementModule
configure, dispose
 
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

ManualAutoIncrementModule

public ManualAutoIncrementModule()
Method Detail

getPostValue

public java.lang.Object getPostValue(org.apache.avalon.framework.configuration.Configuration tableConf,
                                     org.apache.avalon.framework.configuration.Configuration columnConf,
                                     org.apache.avalon.framework.configuration.Configuration modenConf,
                                     java.sql.Connection conn,
                                     java.sql.Statement stmt,
                                     java.util.Map objectModel)
                              throws java.sql.SQLException,
                                     org.apache.avalon.framework.configuration.ConfigurationException
Description copied from interface: AutoIncrementModule
Return key attribute value of last inserted row.
Following copied from interface: org.apache.cocoon.components.modules.database.AutoIncrementModule
Parameters:
name - a String that specifies what the caller thinks would identify a set of parameters. This is mainly a fallback if no modeConf is present.
tableConf - Table's configuration from resource description.
columnConf - column's configuration from resource description.
mdoeConf - this mode's configuration from resource description.
conn - Connection
stmt - Statement that was executed to insert the last row.
request - The request object
Returns:
value representing the last key value value.

includeInQuery

public boolean includeInQuery()
Description copied from interface: AutoIncrementModule
Boolean whether the key attribute column needs to be included in the insert query.
Following copied from interface: org.apache.cocoon.components.modules.database.AutoIncrementModule
Returns:
true if the column is needed, false if the column should be skipped.

includeAsValue

public boolean includeAsValue()
Description copied from interface: AutoIncrementModule
Boolean whether the key attribute needs to be included in the insert query as an attribute value (no subquery).
Following copied from interface: org.apache.cocoon.components.modules.database.AutoIncrementModule
Returns:
true if a value is needed, false if a subquery expression is used or the column is skipped altogether.

getPreValue

public java.lang.Object getPreValue(org.apache.avalon.framework.configuration.Configuration tableConf,
                                    org.apache.avalon.framework.configuration.Configuration columnConf,
                                    org.apache.avalon.framework.configuration.Configuration modeConf,
                                    java.sql.Connection conn,
                                    java.util.Map objectModel)
                             throws java.sql.SQLException,
                                    org.apache.avalon.framework.configuration.ConfigurationException
Description copied from interface: AutoIncrementModule
Provide the value for the key attribute column. If a value for the key value column is needed (i.e. the column is not skipped), this value is computed here.
Following copied from interface: org.apache.cocoon.components.modules.database.AutoIncrementModule
Parameters:
tableConf - Table's configuration from resource description.
columnConf - column's configuration from resource description.
mdoeConf - this mode's configuration from resource description.
conn - Connection
request - The request object
idx - In case of multiple rows to be inserted, index to the desired row
Returns:
exact value for key attribute column

getSubquery

public java.lang.String getSubquery(org.apache.avalon.framework.configuration.Configuration tableConf,
                                    org.apache.avalon.framework.configuration.Configuration columnConf,
                                    org.apache.avalon.framework.configuration.Configuration modeConf)
                             throws org.apache.avalon.framework.configuration.ConfigurationException
Description copied from interface: AutoIncrementModule
Provide subquery string for the key attribute column. If a value for the autoincrement column is needed (i.e. the column is not skipped), and the value can be determined through a nested subquery, this function provides the subquery as a string.
Following copied from interface: org.apache.cocoon.components.modules.database.AutoIncrementModule
Returns:
subquery string for autoincrement column.

setSelectQuery

protected final void setSelectQuery(java.lang.String tableName,
                                    org.apache.avalon.framework.configuration.Configuration entry)
                             throws org.apache.avalon.framework.configuration.ConfigurationException
Set the String representation of the MaxID lookup statement. This is mapped to the Configuration object itself, so if it doesn't exist, it will be created.

getSelectQuery

protected final java.lang.String getSelectQuery(java.lang.String tableName,
                                                org.apache.avalon.framework.configuration.Configuration entry)
                                         throws org.apache.avalon.framework.configuration.ConfigurationException


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.