nl.knowledgeplaza.util
Class JdbcUtil

java.lang.Object
  extended by nl.knowledgeplaza.util.JdbcUtil

public class JdbcUtil
extends java.lang.Object

Several convenience methods for JDBC related tasks. TODO: can we push in some pooling and optional caching? TODO: we use a list-of-maps, which is very memory intensive. A map-of-lists would be better, or even beter: a single class encapsulating that (ResultSet? HA!).

Version:
$Revision: 1.19 $

Nested Class Summary
static class JdbcUtil.JdbcList
           
static class JdbcUtil.JdbcMap
           
static class JdbcUtil.Preprocess
          An interface for Preprocessing during the run
static class JdbcUtil.SyncDescriptor
          Class that provides all data needed for the synchronizeTableFullOneWay methods.
 
Field Summary
static java.lang.String[] EMPTY_STRING_ARRAY
           
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
JdbcUtil()
           
 
Method Summary
static java.lang.String buildSqlDeleteStatement(java.lang.String tablename, java.lang.String[] keys)
          Build the SQL statement that checks if a certain record exists select 1 from table where key=?, ...
static java.lang.String buildSqlInsertStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys)
          Build an insert statement with the same parameter list as the update statement would have.
static java.lang.String buildSqlSelectAllStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys)
           
static java.lang.String buildSqlSelectAllStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys, java.lang.String whereclause)
          Build the SQL statement that selects the specified fields of one record select field, ...
static java.lang.String buildSqlSelectChangedStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys)
          Build the select statement that checks if any of the fields of the record have changed (using the key to identify record) select 1 from table where (fields<>? or ...) and key=? and ...
static java.lang.String buildSqlSelectExistsStatement(java.lang.String tablename, java.lang.String[] keys)
           
static java.lang.String buildSqlSelectExistsStatement(java.lang.String tablename, java.lang.String[] keys, java.lang.String whereclause)
          Build the SQL statement that checks if a certain record exists select 1 from table where key=?, ...
static java.lang.String buildSqlSelectStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys)
          Build the SQL statement that selects the specified fields of one record select field, ...
static java.lang.String buildSqlUpdateStatement(java.lang.String tablename, java.lang.String[] fields, java.lang.String[] keys)
          Build an update statement with the same parameter list as the insert statement would have.
static java.sql.Connection close(java.sql.Connection c)
          Close and wrap the possible but highly unlikely exception in a RuntimeException
static java.sql.PreparedStatement close(java.sql.PreparedStatement c)
          Close and wrap the possible but highly unlikely exception in a RuntimeException
static java.sql.ResultSet close(java.sql.ResultSet c)
          Close and wrap the possible but highly unlikely exception in a RuntimeException
static java.sql.Statement close(java.sql.Statement c)
          Close and wrap the possible but highly unlikely exception in a RuntimeException
static void commit(java.sql.Connection connection)
          Commit but throw a runtime exception instead of a SQLExeception.
static int determineColumnType(java.sql.Connection connection, java.lang.String tableAndColumnName)
          Return the java.sql.Types for a column NOTE: it may be smart to cache the results
static int determineColumnType(java.sql.Connection connection, java.lang.String tableName, java.lang.String columnName)
          Return the java.sql.Types for a column NOTE: it may be smart to cache the results
static int execute(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static int execute(java.sql.Connection connection, java.lang.String sql)
          Execute a single SQL
static int execute(java.sql.Connection connection, java.lang.String sql, java.lang.Object... parameters)
          Execute a single SQL with parameters
static int execute(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static int execute(java.sql.PreparedStatement preparedStatement)
           
static int execute(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static int execute(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Execute a single SQL with parameters
static java.lang.Object getDefaultValueFor(int lType)
          Return a default value for all java.sql.Types
static int getFieldLength(java.sql.Connection connection, java.lang.String tablenamePlusColumnname)
          Determines the length of a field using metadata
static int getFieldLength(java.sql.Connection connection, java.lang.String tablename, java.lang.String columnname)
          Determines the length of a field using metadata
static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection, java.lang.String id)
          Get a single value from the sequence table: create table seq(seq_id varchar(20), seq_val integer default 0, primary key(seq_id));
static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection, java.lang.String tableName, java.lang.String idColumnName, java.lang.String id, java.lang.String valueColumnName)
          Get a single value from a sequence table
static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection, java.lang.String tableName, java.lang.String idColumnName, java.lang.String id, java.lang.String valueColumnName, int increment)
          Get a value block from a sequence table
static java.lang.Number getNextValueFromSequenceTableAndCheck(java.sql.Connection connection, java.lang.String tableName, java.lang.String idColumnName, java.lang.String id, java.lang.String valueColumnName, java.lang.String sql, int maxTries)
          Get a single value from a sequence table
static boolean hasAtLeastOneRecord(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static boolean hasAtLeastOneRecord(java.sql.Connection connection, java.lang.String sql)
           
static boolean hasAtLeastOneRecord(java.sql.Connection connection, java.lang.String sql, java.lang.Object... parameters)
          Check to see if the resultset has enough records
static boolean hasAtLeastOneRecord(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement)
           
static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Check to see if the resultset has enough records
static boolean hasEnoughRecords(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static boolean hasEnoughRecords(java.sql.Connection connection, java.lang.String sql)
           
static boolean hasEnoughRecords(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static boolean hasEnoughRecords(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters, int numberOfRecords)
          Check to see if the resultset has enough records
static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement)
           
static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters, int numberOfRecords)
          Check to see if the resultset has enough records
static boolean isColumnTypeDateOrTime(int type)
          Determine if the java.sql.Types is a date
static boolean isColumnTypeNumber(int type)
          Determine if the java.sql.Types is a number
static boolean isColumnTypeString(int type)
          Determine if the java.sql.Types is a date
static void main(java.lang.String[] args)
          Some quick unit tests
static java.lang.Object query(java.sql.Connection connection, java.lang.String sql)
          Fetch one row, one field
static java.lang.Object query(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
          Fetch one row, one field
static java.lang.Object query(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Fetch one row, one field
static java.util.Map queryAsKeyValueMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
          Fetch key value pairs (1st first is key, 2nd is value, rest is ignored)
static java.util.Map queryAsKeyValueMap(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Fetch key value pairs (1st first is key, 2nd is value, rest is ignored)
static java.util.List queryAsList(java.sql.Connection connection, java.lang.String sql)
          Fetch multiple rows, one field
static java.util.List queryAsList(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
          Fetch multiple rows, one field
static java.util.List queryAsList(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Fetch multiple rows, one field
static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.Connection connection, java.lang.String sql)
          Fetch multiple rows, multiple fields
static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
          Fetch multiple rows, multiple fields
static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Fetch multiple rows, multiple fields
static JdbcUtil.JdbcMap queryAsMap(java.sql.Connection connection, java.lang.String sql)
          Fetch one row, multiple fields
static JdbcUtil.JdbcMap queryAsMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
          Fetch one row, multiple fields
static JdbcUtil.JdbcMap queryAsMap(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
          Fetch one row, multiple fields
static void rollback(java.sql.Connection connection)
          Commit but throw a runtime exception instead of a SQLExeception.
static java.lang.Object sanatizeParameter(java.lang.Object p)
          try to convert parameters to something JDBC will accept, like Calendar to java.sql.Date
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection, java.lang.String sql)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
           
static java.util.List selectManyRowsFirstField(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static java.util.List selectManyRowsFirstField(java.sql.Connection connection, java.lang.String sql)
           
static java.util.List selectManyRowsFirstField(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static java.util.List selectManyRowsFirstField(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
           
static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement)
           
static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection, java.lang.String sql)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection, java.lang.String sql, java.lang.Object parameter)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection, java.lang.String sql, java.lang.Object[] parameters)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
           
static java.lang.Object selectOneRowOneField(java.sql.Connection connection, SqlBuilder sqlBuilder)
           
static java.lang.Object selectOneRowOneField(java.sql.Connection connection, java.lang.String sql)
           
static java.lang.Object selectOneRowOneField(java.sql.Connection connection, java.lang.String sql, java.lang.Object... parameters)
           
static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement)
           
static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement, java.lang.Object parameter)
           
static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement, java.lang.Object[] parameters)
           
static void setParameters(java.sql.PreparedStatement preparedStatement, java.lang.Object... parameters)
          set parameters to a prepared statement
static void synchronizeTableFullOneWay_Copy(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String fromTablename, java.lang.String toTablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j, JdbcUtil.Preprocess preprocess)
          Insert in the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_Delete(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String tablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j)
          Remove any records in the to connection that do not exist in the form connection
static void synchronizeTableFullOneWay_Delete(java.sql.Connection fromConnection, java.lang.String fromTablename, java.lang.String[] fromKeys, java.lang.String[] fromFields, java.sql.Connection toConnection, java.lang.String toTablename, java.lang.String[] toKeys, java.lang.String[] toFields, int commitEvery, org.apache.log4j.Logger log4j)
          Remove any records in the to connection that do not exist in the form connection
static void synchronizeTableFullOneWay_Delete(JdbcUtil.SyncDescriptor syncDescriptor, org.apache.log4j.Logger log4j)
          Remove any records in the to connection that do not exist in the form connection
static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String tablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j)
          Insert in the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String fromTablename, java.lang.String toTablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j)
          Insert in the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String fromTablename, java.lang.String toTablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j, JdbcUtil.Preprocess preprocess)
          Insert in the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_InsertUpdate(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String tablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j)
          Update the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_InsertUpdate(java.sql.Connection fromConnection, java.lang.String fromTablename, java.lang.String[] fromKeys, java.lang.String[] fromFields, java.sql.Connection toConnection, java.lang.String toTablename, java.lang.String[] toKeys, java.lang.String[] toFields, int commitEvery, org.apache.log4j.Logger log4j)
          Update the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay_InsertUpdate(JdbcUtil.SyncDescriptor syncDescriptor, org.apache.log4j.Logger log4j)
          Update the table in the to connection with any missing records in relation to the from connection
static void synchronizeTableFullOneWay(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String tablename, java.lang.String[] keys, java.lang.String[] fields, int commitEvery, org.apache.log4j.Logger log4j)
          Insert, update or delete record so that the table in the to connection becomes identical to the from connection
static void synchronizeTableFullOneWay(java.sql.Connection fromConnection, java.sql.Connection toConnection, java.lang.String fromSchemaName, java.lang.String fromTablename, int commitEvery, org.apache.log4j.Logger log4j)
          Sync a table with all fields
static void synchronizeTableFullOneWay(java.sql.Connection fromConnection, java.lang.String fromTablename, java.lang.String[] fromKeys, java.lang.String[] fromFields, java.sql.Connection toConnection, java.lang.String toTablename, java.lang.String[] toKeys, java.lang.String[] toFields, int commitEvery, org.apache.log4j.Logger log4j)
          Insert, update or delete record so that the table in the to connection becomes identical to the from connection
static void synchronizeTableFullOneWay(JdbcUtil.SyncDescriptor syncDescriptor, org.apache.log4j.Logger log4j)
          Insert, update or delete record so that the table in the to connection becomes identical to the from connection
static boolean tableExists(java.sql.Connection connection, java.lang.String tableName)
          Check if a table exists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

EMPTY_STRING_ARRAY

public static final java.lang.String[] EMPTY_STRING_ARRAY
Constructor Detail

JdbcUtil

public JdbcUtil()
Method Detail

buildSqlSelectAllStatement

public static java.lang.String buildSqlSelectAllStatement(java.lang.String tablename,
                                                          java.lang.String[] fields,
                                                          java.lang.String[] keys,
                                                          java.lang.String whereclause)
Build the SQL statement that selects the specified fields of one record select field, ... from table Optionally a where clause can be specified

Parameters:
tableName -
fields -
keys -
whereclause -

buildSqlSelectAllStatement

public static java.lang.String buildSqlSelectAllStatement(java.lang.String tablename,
                                                          java.lang.String[] fields,
                                                          java.lang.String[] keys)

buildSqlSelectStatement

public static java.lang.String buildSqlSelectStatement(java.lang.String tablename,
                                                       java.lang.String[] fields,
                                                       java.lang.String[] keys)
Build the SQL statement that selects the specified fields of one record select field, ... from table where key=?, ...

Parameters:
tableName -
fields -
keys -

buildSqlSelectExistsStatement

public static java.lang.String buildSqlSelectExistsStatement(java.lang.String tablename,
                                                             java.lang.String[] keys,
                                                             java.lang.String whereclause)
Build the SQL statement that checks if a certain record exists select 1 from table where key=?, ...

Parameters:
tableName -
keys -

buildSqlSelectExistsStatement

public static java.lang.String buildSqlSelectExistsStatement(java.lang.String tablename,
                                                             java.lang.String[] keys)

buildSqlInsertStatement

public static java.lang.String buildSqlInsertStatement(java.lang.String tablename,
                                                       java.lang.String[] fields,
                                                       java.lang.String[] keys)
Build an insert statement with the same parameter list as the update statement would have. This means that there is only one set of "set" calls needed to fill either the insert or update. insert into table(fields..., keys...) values (?, ..., ?)

Parameters:
tableName -
fields -
keys -

buildSqlUpdateStatement

public static java.lang.String buildSqlUpdateStatement(java.lang.String tablename,
                                                       java.lang.String[] fields,
                                                       java.lang.String[] keys)
Build an update statement with the same parameter list as the insert statement would have. This means that there is only one set of "set" calls needed to fill either the insert or update. update table set field=?, ... where key=?, ...

Parameters:
tableName -
fields -
keys -

buildSqlDeleteStatement

public static java.lang.String buildSqlDeleteStatement(java.lang.String tablename,
                                                       java.lang.String[] keys)
Build the SQL statement that checks if a certain record exists select 1 from table where key=?, ...

Parameters:
tableName -
keys -

buildSqlSelectChangedStatement

public static java.lang.String buildSqlSelectChangedStatement(java.lang.String tablename,
                                                              java.lang.String[] fields,
                                                              java.lang.String[] keys)
Build the select statement that checks if any of the fields of the record have changed (using the key to identify record) select 1 from table where (fields<>? or ...) and key=? and ...

Parameters:
tableName -
fields -
keys -

close

public static java.sql.Connection close(java.sql.Connection c)
Close and wrap the possible but highly unlikely exception in a RuntimeException

Parameters:
c -

close

public static java.sql.Statement close(java.sql.Statement c)
Close and wrap the possible but highly unlikely exception in a RuntimeException

Parameters:
c -

close

public static java.sql.PreparedStatement close(java.sql.PreparedStatement c)
Close and wrap the possible but highly unlikely exception in a RuntimeException

Parameters:
c -

close

public static java.sql.ResultSet close(java.sql.ResultSet c)
Close and wrap the possible but highly unlikely exception in a RuntimeException

Parameters:
c -

execute

public static int execute(java.sql.Connection connection,
                          java.lang.String sql)
                   throws java.sql.SQLException
Execute a single SQL

Parameters:
connection -
sql -
Returns:
number of rows modified
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.Connection connection,
                          java.lang.String sql,
                          java.lang.Object... parameters)
                   throws java.sql.SQLException
Execute a single SQL with parameters

Parameters:
connection -
sql -
Returns:
number of rows modified
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.Connection connection,
                          java.lang.String sql,
                          java.lang.Object parameter)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.PreparedStatement preparedStatement,
                          java.lang.Object[] parameters)
                   throws java.sql.SQLException
Execute a single SQL with parameters

Parameters:
connection -
sql -
Returns:
number of rows modified
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.PreparedStatement preparedStatement,
                          java.lang.Object parameter)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.PreparedStatement preparedStatement)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

execute

public static int execute(java.sql.Connection connection,
                          SqlBuilder sqlBuilder)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

rollback

public static void rollback(java.sql.Connection connection)
Commit but throw a runtime exception instead of a SQLExeception. USE WITH CASE.

Parameters:
connection -

commit

public static void commit(java.sql.Connection connection)
Commit but throw a runtime exception instead of a SQLExeception. USE WITH CASE.

Parameters:
connection -

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.Connection connection,
                                          java.lang.String sql,
                                          java.lang.Object... parameters)
                                   throws java.sql.SQLException
Check to see if the resultset has enough records

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.Connection connection,
                                          java.lang.String sql,
                                          java.lang.Object parameter)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.Connection connection,
                                          java.lang.String sql)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement,
                                          java.lang.Object[] parameters)
                                   throws java.sql.SQLException
Check to see if the resultset has enough records

Parameters:
preparedStatement -
parameters -
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement,
                                          java.lang.Object parameter)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.PreparedStatement preparedStatement)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

hasAtLeastOneRecord

public static boolean hasAtLeastOneRecord(java.sql.Connection connection,
                                          SqlBuilder sqlBuilder)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.Connection connection,
                                       java.lang.String sql,
                                       java.lang.Object[] parameters,
                                       int numberOfRecords)
                                throws java.sql.SQLException
Check to see if the resultset has enough records

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.Connection connection,
                                       java.lang.String sql,
                                       java.lang.Object parameter)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.Connection connection,
                                       java.lang.String sql)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement,
                                       java.lang.Object[] parameters,
                                       int numberOfRecords)
                                throws java.sql.SQLException
Check to see if the resultset has enough records

Parameters:
preparedStatement -
parameters -
numberOfRecords -
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement,
                                       java.lang.Object parameter)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.PreparedStatement preparedStatement)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

hasEnoughRecords

public static boolean hasEnoughRecords(java.sql.Connection connection,
                                       SqlBuilder sqlBuilder)
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

tableExists

public static boolean tableExists(java.sql.Connection connection,
                                  java.lang.String tableName)
Check if a table exists

Parameters:
connection -
tableName -

query

public static java.lang.Object query(java.sql.Connection connection,
                                     java.lang.String sql)
                              throws java.sql.SQLException
Fetch one row, one field

Parameters:
connection -
sql -
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.Connection connection,
                                                    java.lang.String sql)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

query

public static java.lang.Object query(java.sql.Connection connection,
                                     java.lang.String sql,
                                     java.lang.Object[] parameters)
                              throws java.sql.SQLException
Fetch one row, one field

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.Connection connection,
                                                    java.lang.String sql,
                                                    java.lang.Object... parameters)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

query

public static java.lang.Object query(java.sql.PreparedStatement preparedStatement,
                                     java.lang.Object[] parameters)
                              throws java.sql.SQLException
Fetch one row, one field

Parameters:
connection -
preparedStatement -
parameters -
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement,
                                                    java.lang.Object[] parameters)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement,
                                                    java.lang.Object parameter)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.PreparedStatement preparedStatement)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowOneField

public static java.lang.Object selectOneRowOneField(java.sql.Connection connection,
                                                    SqlBuilder sqlBuilder)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsList

public static java.util.List queryAsList(java.sql.Connection connection,
                                         java.lang.String sql)
                                  throws java.sql.SQLException
Fetch multiple rows, one field

Parameters:
connection -
sql -
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.Connection connection,
                                                      java.lang.String sql)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsList

public static java.util.List queryAsList(java.sql.Connection connection,
                                         java.lang.String sql,
                                         java.lang.Object[] parameters)
                                  throws java.sql.SQLException
Fetch multiple rows, one field

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.Connection connection,
                                                      java.lang.String sql,
                                                      java.lang.Object[] parameters)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.Connection connection,
                                                      java.lang.String sql,
                                                      java.lang.Object parameter)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsList

public static java.util.List queryAsList(java.sql.PreparedStatement preparedStatement,
                                         java.lang.Object[] parameters)
                                  throws java.sql.SQLException
Fetch multiple rows, one field

Parameters:
connection -
preparedStatement -
parameters -
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement,
                                                      java.lang.Object[] parameters)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement,
                                                      java.lang.Object parameter)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.PreparedStatement preparedStatement)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstField

public static java.util.List selectManyRowsFirstField(java.sql.Connection connection,
                                                      SqlBuilder sqlBuilder)
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsMap

public static JdbcUtil.JdbcMap queryAsMap(java.sql.Connection connection,
                                          java.lang.String sql)
                                   throws java.sql.SQLException
Fetch one row, multiple fields

Parameters:
connection -
sql -
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection,
                                                     java.lang.String sql)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsMap

public static JdbcUtil.JdbcMap queryAsMap(java.sql.Connection connection,
                                          java.lang.String sql,
                                          java.lang.Object[] parameters)
                                   throws java.sql.SQLException
Fetch one row, multiple fields

Parameters:
connection -
sql -
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection,
                                                     java.lang.String sql,
                                                     java.lang.Object[] parameters)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection,
                                                     java.lang.String sql,
                                                     java.lang.Object parameter)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsMap

public static JdbcUtil.JdbcMap queryAsMap(java.sql.PreparedStatement preparedStatement,
                                          java.lang.Object[] parameters)
                                   throws java.sql.SQLException
Fetch one row, multiple fields

Parameters:
connection -
preparedStatement -
parameters -
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement,
                                                     java.lang.Object[] parameters)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement,
                                                     java.lang.Object parameter)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.PreparedStatement preparedStatement)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

selectOneRowAllFields

public static JdbcUtil.JdbcMap selectOneRowAllFields(java.sql.Connection connection,
                                                     SqlBuilder sqlBuilder)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsListOfMaps

public static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.Connection connection,
                                                  java.lang.String sql)
                                           throws java.sql.SQLException
Fetch multiple rows, multiple fields

Parameters:
connection -
sql -
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection,
                                                                   java.lang.String sql)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsListOfMaps

public static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.Connection connection,
                                                  java.lang.String sql,
                                                  java.lang.Object[] parameters)
                                           throws java.sql.SQLException
Fetch multiple rows, multiple fields

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection,
                                                                   java.lang.String sql,
                                                                   java.lang.Object[] parameters)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection,
                                                                   java.lang.String sql,
                                                                   java.lang.Object parameter)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsListOfMaps

public static JdbcUtil.JdbcList queryAsListOfMaps(java.sql.PreparedStatement preparedStatement,
                                                  java.lang.Object[] parameters)
                                           throws java.sql.SQLException
Fetch multiple rows, multiple fields

Parameters:
connection -
preparedStatement -
parameters -
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement,
                                                                   java.lang.Object[] parameters)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement,
                                                                   java.lang.Object parameter)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.PreparedStatement preparedStatement)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsAllFieldsAsListOfMap

public static JdbcUtil.JdbcList selectManyRowsAllFieldsAsListOfMap(java.sql.Connection connection,
                                                                   SqlBuilder sqlBuilder)
                                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsKeyValueMap

public static java.util.Map queryAsKeyValueMap(java.sql.Connection connection,
                                               java.lang.String sql,
                                               java.lang.Object[] parameters)
                                        throws java.sql.SQLException
Fetch key value pairs (1st first is key, 2nd is value, rest is ignored)

Parameters:
connection -
sql -
parameters -
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection,
                                                                      java.lang.String sql,
                                                                      java.lang.Object[] parameters)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection,
                                                                      java.lang.String sql,
                                                                      java.lang.Object parameter)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

queryAsKeyValueMap

public static java.util.Map queryAsKeyValueMap(java.sql.PreparedStatement preparedStatement,
                                               java.lang.Object[] parameters)
                                        throws java.sql.SQLException
Fetch key value pairs (1st first is key, 2nd is value, rest is ignored)

Parameters:
connection -
preparedStatement -
parameters -
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement,
                                                                      java.lang.Object[] parameters)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement,
                                                                      java.lang.Object parameter)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.PreparedStatement preparedStatement)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

selectManyRowsFirstTwoFieldsAsKeyValueMap

public static java.util.Map selectManyRowsFirstTwoFieldsAsKeyValueMap(java.sql.Connection connection,
                                                                      SqlBuilder sqlBuilder)
                                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

setParameters

public static void setParameters(java.sql.PreparedStatement preparedStatement,
                                 java.lang.Object... parameters)
                          throws java.sql.SQLException
set parameters to a prepared statement

Throws:
java.sql.SQLException

sanatizeParameter

public static java.lang.Object sanatizeParameter(java.lang.Object p)
try to convert parameters to something JDBC will accept, like Calendar to java.sql.Date


synchronizeTableFullOneWay

public static void synchronizeTableFullOneWay(java.sql.Connection fromConnection,
                                              java.sql.Connection toConnection,
                                              java.lang.String tablename,
                                              java.lang.String[] keys,
                                              java.lang.String[] fields,
                                              int commitEvery,
                                              org.apache.log4j.Logger log4j)
                                       throws java.sql.SQLException
Insert, update or delete record so that the table in the to connection becomes identical to the from connection

Parameters:
fromConnection -
toConnection -
tablename -
keys -
fields -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay

public static void synchronizeTableFullOneWay(java.sql.Connection fromConnection,
                                              java.lang.String fromTablename,
                                              java.lang.String[] fromKeys,
                                              java.lang.String[] fromFields,
                                              java.sql.Connection toConnection,
                                              java.lang.String toTablename,
                                              java.lang.String[] toKeys,
                                              java.lang.String[] toFields,
                                              int commitEvery,
                                              org.apache.log4j.Logger log4j)
                                       throws java.sql.SQLException
Insert, update or delete record so that the table in the to connection becomes identical to the from connection

Parameters:
fromConnection -
fromTablename -
fromKeys -
fromFields -
toConnection -
toTablename -
toKeys -
toFields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay

public static void synchronizeTableFullOneWay(JdbcUtil.SyncDescriptor syncDescriptor,
                                              org.apache.log4j.Logger log4j)
                                       throws java.sql.SQLException
Insert, update or delete record so that the table in the to connection becomes identical to the from connection

Parameters:
syncDescriptor -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Insert

public static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection,
                                                     java.sql.Connection toConnection,
                                                     java.lang.String tablename,
                                                     java.lang.String[] keys,
                                                     java.lang.String[] fields,
                                                     int commitEvery,
                                                     org.apache.log4j.Logger log4j)
                                              throws java.sql.SQLException
Insert in the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
toConnection -
tablename -
keys -
fields -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Insert

public static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection,
                                                     java.sql.Connection toConnection,
                                                     java.lang.String fromTablename,
                                                     java.lang.String toTablename,
                                                     java.lang.String[] keys,
                                                     java.lang.String[] fields,
                                                     int commitEvery,
                                                     org.apache.log4j.Logger log4j)
                                              throws java.sql.SQLException
Insert in the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
toConnection -
fromTablename -
toTablename -
keys -
fields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Copy

public static void synchronizeTableFullOneWay_Copy(java.sql.Connection fromConnection,
                                                   java.sql.Connection toConnection,
                                                   java.lang.String fromTablename,
                                                   java.lang.String toTablename,
                                                   java.lang.String[] keys,
                                                   java.lang.String[] fields,
                                                   int commitEvery,
                                                   org.apache.log4j.Logger log4j,
                                                   JdbcUtil.Preprocess preprocess)
                                            throws java.sql.SQLException
Insert in the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
toConnection -
fromTablename -
toTablename -
keys -
fields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Insert

public static void synchronizeTableFullOneWay_Insert(java.sql.Connection fromConnection,
                                                     java.sql.Connection toConnection,
                                                     java.lang.String fromTablename,
                                                     java.lang.String toTablename,
                                                     java.lang.String[] keys,
                                                     java.lang.String[] fields,
                                                     int commitEvery,
                                                     org.apache.log4j.Logger log4j,
                                                     JdbcUtil.Preprocess preprocess)
                                              throws java.sql.SQLException
Insert in the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
toConnection -
fromTablename -
toTablename -
keys -
fields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_InsertUpdate

public static void synchronizeTableFullOneWay_InsertUpdate(java.sql.Connection fromConnection,
                                                           java.sql.Connection toConnection,
                                                           java.lang.String tablename,
                                                           java.lang.String[] keys,
                                                           java.lang.String[] fields,
                                                           int commitEvery,
                                                           org.apache.log4j.Logger log4j)
                                                    throws java.sql.SQLException
Update the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
toConnection -
tablename -
keys -
fields -
log4j -
Throws:
java.sql.SQLException - TODO: return a list of PK tuples to simplify delete

synchronizeTableFullOneWay_InsertUpdate

public static void synchronizeTableFullOneWay_InsertUpdate(java.sql.Connection fromConnection,
                                                           java.lang.String fromTablename,
                                                           java.lang.String[] fromKeys,
                                                           java.lang.String[] fromFields,
                                                           java.sql.Connection toConnection,
                                                           java.lang.String toTablename,
                                                           java.lang.String[] toKeys,
                                                           java.lang.String[] toFields,
                                                           int commitEvery,
                                                           org.apache.log4j.Logger log4j)
                                                    throws java.sql.SQLException
Update the table in the to connection with any missing records in relation to the from connection

Parameters:
fromConnection -
fromTablename -
fromKeys -
fromFields -
toConnection -
toTablename -
toKeys -
toFields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_InsertUpdate

public static void synchronizeTableFullOneWay_InsertUpdate(JdbcUtil.SyncDescriptor syncDescriptor,
                                                           org.apache.log4j.Logger log4j)
                                                    throws java.sql.SQLException
Update the table in the to connection with any missing records in relation to the from connection

Parameters:
syncDescriptor -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Delete

public static void synchronizeTableFullOneWay_Delete(java.sql.Connection fromConnection,
                                                     java.sql.Connection toConnection,
                                                     java.lang.String tablename,
                                                     java.lang.String[] keys,
                                                     java.lang.String[] fields,
                                                     int commitEvery,
                                                     org.apache.log4j.Logger log4j)
                                              throws java.sql.SQLException
Remove any records in the to connection that do not exist in the form connection

Parameters:
fromConnection -
toConnection -
tablename -
keys -
fields -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Delete

public static void synchronizeTableFullOneWay_Delete(java.sql.Connection fromConnection,
                                                     java.lang.String fromTablename,
                                                     java.lang.String[] fromKeys,
                                                     java.lang.String[] fromFields,
                                                     java.sql.Connection toConnection,
                                                     java.lang.String toTablename,
                                                     java.lang.String[] toKeys,
                                                     java.lang.String[] toFields,
                                                     int commitEvery,
                                                     org.apache.log4j.Logger log4j)
                                              throws java.sql.SQLException
Remove any records in the to connection that do not exist in the form connection

Parameters:
fromConnection -
toConnection -
tablename -
keys -
fields -
commitEvery -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay_Delete

public static void synchronizeTableFullOneWay_Delete(JdbcUtil.SyncDescriptor syncDescriptor,
                                                     org.apache.log4j.Logger log4j)
                                              throws java.sql.SQLException
Remove any records in the to connection that do not exist in the form connection

Parameters:
syncDescriptor -
log4j -
Throws:
java.sql.SQLException

synchronizeTableFullOneWay

public static void synchronizeTableFullOneWay(java.sql.Connection fromConnection,
                                              java.sql.Connection toConnection,
                                              java.lang.String fromSchemaName,
                                              java.lang.String fromTablename,
                                              int commitEvery,
                                              org.apache.log4j.Logger log4j)
                                       throws java.sql.SQLException
Sync a table with all fields

Parameters:
fromConnection -
toConnection -
fromSchemaName -
fromTablename -
commitEvery -
log4j -
Throws:
java.sql.SQLException

getNextValueFromSequenceTable

public static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection,
                                                             java.lang.String tableName,
                                                             java.lang.String idColumnName,
                                                             java.lang.String id,
                                                             java.lang.String valueColumnName,
                                                             int increment)
                                                      throws java.sql.SQLException
Get a value block from a sequence table

Parameters:
connection - this connection should have auto commit set to false, otherwise there is a small gap where things may go wrong
tableName -
idColumnName -
id -
valueColumnName -
increment -
Returns:
Number or null if nothing was allocated
Throws:
java.sql.SQLException

getNextValueFromSequenceTable

public static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection,
                                                             java.lang.String tableName,
                                                             java.lang.String idColumnName,
                                                             java.lang.String id,
                                                             java.lang.String valueColumnName)
                                                      throws java.sql.SQLException
Get a single value from a sequence table

Parameters:
connection -
tableName -
idColumnName -
id -
valueColumnName -
Returns:
Number or null if nothing was allocated
Throws:
java.sql.SQLException

getNextValueFromSequenceTable

public static java.lang.Number getNextValueFromSequenceTable(java.sql.Connection connection,
                                                             java.lang.String id)
                                                      throws java.sql.SQLException
Get a single value from the sequence table: create table seq(seq_id varchar(20), seq_val integer default 0, primary key(seq_id));

Parameters:
connection -
id -
Returns:
Number or null if nothing was allocated
Throws:
java.sql.SQLException

getNextValueFromSequenceTableAndCheck

public static java.lang.Number getNextValueFromSequenceTableAndCheck(java.sql.Connection connection,
                                                                     java.lang.String tableName,
                                                                     java.lang.String idColumnName,
                                                                     java.lang.String id,
                                                                     java.lang.String valueColumnName,
                                                                     java.lang.String sql,
                                                                     int maxTries)
                                                              throws java.sql.SQLException
Get a single value from a sequence table

Parameters:
connection -
tableName - sequence table name
idColumnName - sequence table id column name
id - the id stored in the id column
valueColumnName - sequence table value column name
sql - the SQL that validates is the number already is used a a PK
maxTries - number of tries to get a PK
Returns:
Number or null if nothing was allocated
Throws:
java.sql.SQLException

determineColumnType

public static int determineColumnType(java.sql.Connection connection,
                                      java.lang.String tableAndColumnName)
Return the java.sql.Types for a column NOTE: it may be smart to cache the results


determineColumnType

public static int determineColumnType(java.sql.Connection connection,
                                      java.lang.String tableName,
                                      java.lang.String columnName)
Return the java.sql.Types for a column NOTE: it may be smart to cache the results


isColumnTypeNumber

public static boolean isColumnTypeNumber(int type)
Determine if the java.sql.Types is a number


isColumnTypeDateOrTime

public static boolean isColumnTypeDateOrTime(int type)
Determine if the java.sql.Types is a date


isColumnTypeString

public static boolean isColumnTypeString(int type)
Determine if the java.sql.Types is a date


getDefaultValueFor

public static java.lang.Object getDefaultValueFor(int lType)
Return a default value for all java.sql.Types

Parameters:
lType -
Returns:

getFieldLength

public static int getFieldLength(java.sql.Connection connection,
                                 java.lang.String tablename,
                                 java.lang.String columnname)
Determines the length of a field using metadata

Parameters:
connection -
tablename -
columnname -
Returns:
size or -1 when unknown

getFieldLength

public static int getFieldLength(java.sql.Connection connection,
                                 java.lang.String tablenamePlusColumnname)
Determines the length of a field using metadata

Parameters:
connection -
tablenamePlusColumnname - tablename.columnname
Returns:
size or -1 when unknown

main

public static void main(java.lang.String[] args)
Some quick unit tests



Copyright © 2010 KnowledgePlaza. All Rights Reserved.