net.sourceforge.jdbcimporter.util
Class JDBCParameterHelper

java.lang.Object
  extended bynet.sourceforge.jdbcimporter.util.JDBCParameterHelper

public class JDBCParameterHelper
extends java.lang.Object

The JDBCParameterHelper provides a methods to set parameters of a PreparedStatement and retrieve values from a ResultSet.

Version:
0.62
Author:
Chris Nagy

Field Summary
protected  boolean emptyStringAsNull
           
protected static org.apache.commons.logging.Log LOG
          The log for debug information.
 
Constructor Summary
JDBCParameterHelper()
           
 
Method Summary
 boolean compareResultSet(java.sql.ResultSet rset, ImportColumnDef[] columns, int[] compareIndices, ColumnValue[] values)
          Compare the row in the result set with the values given.
 ColumnValue getColumn(java.sql.ResultSet resultSet, int column, ColumnDef def)
          Returns the column value for a given column index in the result set.
 java.lang.String getFullyQualifiedTableName(java.sql.DatabaseMetaData metaData, java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Returns the fully qualified table name (that includes the catalog and the schema).
protected  boolean isStringNull(int type, java.lang.String val)
           
 int[] resolveRowStates(java.sql.Connection con, ImportEntityDef entityDef, java.util.List rows, int[] keyIndices, int[] compareIndices)
          Resolve whether the rows provided where imported into the database by select them based on the key indices.
 void setColumn(java.sql.PreparedStatement pstmt, int column, ColumnDef def, ColumnValue val)
          Set the column value in the prepared statement.
 void setEmptyStringAsNull(boolean flag)
          Sets a flag indicating how empty strings are set in a prepared statement.
 
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.


emptyStringAsNull

protected boolean emptyStringAsNull
Constructor Detail

JDBCParameterHelper

public JDBCParameterHelper()
Method Detail

setEmptyStringAsNull

public void setEmptyStringAsNull(boolean flag)
Sets a flag indicating how empty strings are set in a prepared statement. If the flag is true then empty strings will be treated as null for character columns, otherwise they will be inserted as is.

Parameters:
flag - flag indicating how empty strings are set in a prepared statement

setColumn

public void setColumn(java.sql.PreparedStatement pstmt,
                      int column,
                      ColumnDef def,
                      ColumnValue val)
               throws MalformedDataException
Set the column value in the prepared statement.

Parameters:
pstmt - the prepared statement
column - the column index
def - the column definition
val - the column value
Throws:
MalformedDataException

resolveRowStates

public int[] resolveRowStates(java.sql.Connection con,
                              ImportEntityDef entityDef,
                              java.util.List rows,
                              int[] keyIndices,
                              int[] compareIndices)
Resolve whether the rows provided where imported into the database by select them based on the key indices.

Parameters:
con - the connection
entityDef - the entity def
rows - the rows to resolve
keyIndices - the indices into the entity def columns that represent the primary key
compareIndices - the indices of the entity def columns that need to be compared
Returns:
a list of row states : 0 = row not found or does not match, 1 = row matches

compareResultSet

public boolean compareResultSet(java.sql.ResultSet rset,
                                ImportColumnDef[] columns,
                                int[] compareIndices,
                                ColumnValue[] values)
                         throws java.sql.SQLException
Compare the row in the result set with the values given.

Parameters:
rset - the result set
columns - the list of columns
compareIndices - the indices of the columns that should be compared
values - the column values
Returns:
true if the row matches, otherwise false
Throws:
java.sql.SQLException

getColumn

public ColumnValue getColumn(java.sql.ResultSet resultSet,
                             int column,
                             ColumnDef def)
                      throws java.sql.SQLException
Returns the column value for a given column index in the result set.

Parameters:
resultSet - the result set
column - the column index
def - the column definition
Returns:
the column value
Throws:
java.sql.SQLException

getFullyQualifiedTableName

public java.lang.String getFullyQualifiedTableName(java.sql.DatabaseMetaData metaData,
                                                   java.lang.String catalog,
                                                   java.lang.String schema,
                                                   java.lang.String table)
                                            throws java.sql.SQLException
Returns the fully qualified table name (that includes the catalog and the schema).

Parameters:
metaData - The database meta data
catalog - The catalog
schema - The schema
table - The table
Returns:
The fully qualified table name
Throws:
java.sql.SQLException

isStringNull

protected boolean isStringNull(int type,
                               java.lang.String val)