net.sourceforge.jdbcimporter.engine
Class UpdateEngine

java.lang.Object
  extended bynet.sourceforge.jdbcimporter.engine.UpdateEngine
All Implemented Interfaces:
ImportEngine

public class UpdateEngine
extends java.lang.Object
implements ImportEngine

The UpdateEngine class executes an insert or update sql statement. It determines whether to use an insert or update sql statement by executing a select (based on the primary keys of the table). It will fail if the data to be imported does not contain a column that is part of the primary key.

Version:
0.6
Author:
Chris Nagy

Field Summary
protected static org.apache.commons.logging.Log LOG
          The log for debug information.
static java.lang.String PRIMARY_KEY_PROPERTY
          The property on a column definition that will indicate the the column is a primary key (the value should be 'true').
static java.lang.String SELECT_POSTFIX_PROPERTY
          The property on an entity definition whose value will be appended to the select statement.
static java.lang.String UPDATE_EXPRESSION_PROPERTY
          The property on a column definition whose value will be used as the update expression for that column (the value should contain the character '?').
 
Fields inherited from interface net.sourceforge.jdbcimporter.ImportEngine
BATCH_SUCCESS_ROWS_UNKNOWN
 
Constructor Summary
UpdateEngine()
           
 
Method Summary
 void cleanup()
          Cleans up any resources that the import engine used to import data for the current entity definition.
 void executeBatch()
          Call executeBatch on the allocated statements.
 java.sql.Connection getConnection()
          Returns the database connection to use for importing the row.
protected  java.util.List getDefinedPrimaryKeys()
          Returns the list of primary keys defined in the import xml.
protected  java.util.List getPrimaryKeys(java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Returns the list of primary keys from the DatabaseMeta.
 void importRow(ColumnValue[] values)
          Imports the given set of values as a row into the database
 void init()
          Initializes the import engine with the current entity definition.
 void setBatchMode(boolean flag)
          Sets whether the import will use batch mode.
 void setConnection(java.sql.Connection con)
          Sets the database connection to use for importing the row.
 void setEntityDef(ImportEntityDef entityDef)
          Sets the entity definition to use for importing the row
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static org.apache.commons.logging.Log LOG
The log for debug information.


SELECT_POSTFIX_PROPERTY

public static final java.lang.String SELECT_POSTFIX_PROPERTY
The property on an entity definition whose value will be appended to the select statement.

See Also:
Constant Field Values

PRIMARY_KEY_PROPERTY

public static final java.lang.String PRIMARY_KEY_PROPERTY
The property on a column definition that will indicate the the column is a primary key (the value should be 'true').

See Also:
Constant Field Values

UPDATE_EXPRESSION_PROPERTY

public static final java.lang.String UPDATE_EXPRESSION_PROPERTY
The property on a column definition whose value will be used as the update expression for that column (the value should contain the character '?').

See Also:
Constant Field Values
Constructor Detail

UpdateEngine

public UpdateEngine()
Method Detail

setConnection

public void setConnection(java.sql.Connection con)
Description copied from interface: ImportEngine
Sets the database connection to use for importing the row.

Specified by:
setConnection in interface ImportEngine
Parameters:
con - database connection
See Also:
ImportEngine.setConnection(Connection)

getConnection

public java.sql.Connection getConnection()
Description copied from interface: ImportEngine
Returns the database connection to use for importing the row.

Specified by:
getConnection in interface ImportEngine
Returns:
database connection
See Also:
ImportEngine.getConnection()

setEntityDef

public void setEntityDef(ImportEntityDef entityDef)
Description copied from interface: ImportEngine
Sets the entity definition to use for importing the row

Specified by:
setEntityDef in interface ImportEngine
Parameters:
entityDef - entity definition
See Also:
ImportEngine.setEntityDef(ImportEntityDef)

init

public void init()
          throws java.sql.SQLException
Description copied from interface: ImportEngine
Initializes the import engine with the current entity definition.

Specified by:
init in interface ImportEngine
Throws:
java.sql.SQLException - if a database error occurs during initialization
See Also:
ImportEngine.init()

cleanup

public void cleanup()
             throws java.sql.SQLException
Description copied from interface: ImportEngine
Cleans up any resources that the import engine used to import data for the current entity definition.

Specified by:
cleanup in interface ImportEngine
Throws:
java.sql.SQLException - if a database error occurs during cleanup
See Also:
ImportEngine.cleanup()

importRow

public void importRow(ColumnValue[] values)
               throws java.sql.SQLException,
                      MalformedDataException
Description copied from interface: ImportEngine
Imports the given set of values as a row into the database

Specified by:
importRow in interface ImportEngine
Parameters:
values - the column values for the row
Throws:
java.sql.SQLException - if a database error occurs during the import
MalformedDataException
See Also:
ImportEngine.importRow(ColumnValue[])

getDefinedPrimaryKeys

protected java.util.List getDefinedPrimaryKeys()
Returns the list of primary keys defined in the import xml.

Returns:
list of primary keys

getPrimaryKeys

protected java.util.List getPrimaryKeys(java.lang.String catalog,
                                        java.lang.String schema,
                                        java.lang.String table)
                                 throws java.sql.SQLException
Returns the list of primary keys from the DatabaseMeta.

Parameters:
catalog - The catalog
schema - The schema
table - The table
Returns:
list of primary keys
Throws:
java.sql.SQLException

setBatchMode

public void setBatchMode(boolean flag)
Description copied from interface: ImportEngine
Sets whether the import will use batch mode.

Specified by:
setBatchMode in interface ImportEngine
Parameters:
flag - true if the import will use batch mode
See Also:
ImportEngine.setBatchMode(boolean)

executeBatch

public void executeBatch()
                  throws java.sql.BatchUpdateException
Description copied from interface: ImportEngine
Call executeBatch on the allocated statements.

Specified by:
executeBatch in interface ImportEngine
Throws:
java.sql.BatchUpdateException - If not all rows were imported then throw a BatchUpdateException
See Also:
ImportEngine.executeBatch()