net.sourceforge.squirrel_sql.plugins.dbdiff.util
Class DBUtil

java.lang.Object
  extended by net.sourceforge.squirrel_sql.plugins.dbdiff.util.DBUtil

public class DBUtil
extends Object

A utility class for interacting with the database.


Constructor Summary
DBUtil()
           
 
Method Summary
static boolean containsTable(List<ITableInfo> tableInfos, String table)
           
static ResultSet executeQuery(ISession session, String sql)
          Executes the specified sql statement on the specified connection and returns the ResultSet.
static String fixCase(ISession session, String identifier)
          Uppercase / Lowercase / Mixedcase identifiers are a big problem.
static String getCatSep(ISession session)
           
static int getColumnCount(ISQLConnection sourceConn, ITableInfo ti)
           
static String getColumnList(TableColumnInfo[] colInfoArr)
           
static String getColumnName(ISQLConnection sourceConn, ITableInfo ti, int column)
           
static String[] getColumnNames(ISQLConnection sourceConn, ITableInfo ti)
           
static int getColumnType(ISQLConnection con, ITableInfo ti, int column)
           
static int getColumnType(ISQLConnection con, ITableInfo ti, String columnName)
           
static int[] getColumnTypes(ISQLConnection con, ITableInfo ti)
           
static int[] getColumnTypes(ISQLConnection con, ITableInfo ti, String[] colNames)
           
static String getLastStatement()
           
static String getLastStatementValues()
           
static String getMaxColumnLengthSQL(ISession sourceSession, TableColumnInfo colInfo, String tableName, boolean tableNameIsQualified)
          Gets the SQL statement which can be used to select the maximum length of the current data found in tableName within the specified column.
static String getPKColumnString(ISQLConnection sourceConn, ITableInfo ti)
          Returns a string that looks like: (PK_COL1, PK_COL2, PK_COL3, ...) or null if there is no primary key for the specified table.
static String getQualifiedObjectName(ISession session, String catalogName, String schemaName, String objectName, int sessionType)
          Decide whether or not the session specified needs fully qualified table names (schema.table).
static String getSelectQuery(SessionInfoProvider prov, String columnList, ITableInfo ti)
           
static int getTableCount(ISession session, String catalog, String schema, String tableName, int sessionType)
          Returns a count of the records in the specified table.
static ITableInfo getTableInfo(ISession session, String schema, String tableName)
           
static boolean isBinaryType(TableColumnInfo columnInfo)
          Returns a boolean value indicating whether or not the specified TableColumnInfo represents a database column that holds binary type data.
static int replaceOtherDataType(TableColumnInfo colInfo)
          Takes the specified colInfo, gets the data type to see if it is 1111(OTHER).
static boolean sameDatabaseType(ISession session1, ISession session2)
           
static void setLastStatement(String lastStatement)
           
static void setLastStatementValues(String values)
           
static boolean tableHasForeignKey(String destCatalog, String destSchema, String destTableName, ForeignKeyInfo fkInfo, SessionInfoProvider prov)
           
static boolean tableHasPrimaryKey(ISQLConnection con, ITableInfo ti)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBUtil

public DBUtil()
Method Detail

getPKColumnString

public static String getPKColumnString(ISQLConnection sourceConn,
                                       ITableInfo ti)
                                throws SQLException
Returns a string that looks like: (PK_COL1, PK_COL2, PK_COL3, ...) or null if there is no primary key for the specified table.

Parameters:
sourceConn -
ti -
Returns:
Throws:
SQLException

tableHasForeignKey

public static boolean tableHasForeignKey(String destCatalog,
                                         String destSchema,
                                         String destTableName,
                                         ForeignKeyInfo fkInfo,
                                         SessionInfoProvider prov)

containsTable

public static boolean containsTable(List<ITableInfo> tableInfos,
                                    String table)

executeQuery

public static ResultSet executeQuery(ISession session,
                                     String sql)
                              throws SQLException
Executes the specified sql statement on the specified connection and returns the ResultSet.

Parameters:
con -
sql -
mysqlBigResultFix - if true, provides a work-around which is useful in the case that the connection is to a MySQL database. If the number of rows is large this will prevent the driver from reading them all into client memory. MySQL's normal practice is to do such a thing for performance reasons.
Returns:
Throws:
Exception
SQLException

getTableCount

public static int getTableCount(ISession session,
                                String catalog,
                                String schema,
                                String tableName,
                                int sessionType)
                         throws UserCancelledOperationException
Returns a count of the records in the specified table.

Parameters:
con - the SQLConnection to use to execute the count query.
tableName - the name of the table
Returns:
-1 if the table does not exist, otherwise the record count is returned.
Throws:
UserCancelledOperationException

getTableInfo

public static ITableInfo getTableInfo(ISession session,
                                      String schema,
                                      String tableName)
                               throws SQLException,
                                      org.hibernate.MappingException,
                                      UserCancelledOperationException
Throws:
SQLException
org.hibernate.MappingException
UserCancelledOperationException

replaceOtherDataType

public static int replaceOtherDataType(TableColumnInfo colInfo)
                                throws org.hibernate.MappingException
Takes the specified colInfo, gets the data type to see if it is 1111(OTHER). If so then get the type name and try to match a jdbc type with the same name to get it's type code.

Parameters:
colInfo -
Returns:
Throws:
org.hibernate.MappingException

getColumnType

public static int getColumnType(ISQLConnection con,
                                ITableInfo ti,
                                String columnName)
                         throws SQLException
Parameters:
con -
synonym -
columnName -
Returns:
Throws:
SQLException

getColumnTypes

public static int[] getColumnTypes(ISQLConnection con,
                                   ITableInfo ti,
                                   String[] colNames)
                            throws SQLException
Throws:
SQLException

tableHasPrimaryKey

public static boolean tableHasPrimaryKey(ISQLConnection con,
                                         ITableInfo ti)
                                  throws SQLException
Throws:
SQLException

getColumnList

public static String getColumnList(TableColumnInfo[] colInfoArr)
                            throws SQLException
Parameters:
con -
ti -
Returns:
Throws:
SQLException

getColumnName

public static String getColumnName(ISQLConnection sourceConn,
                                   ITableInfo ti,
                                   int column)
                            throws SQLException
Parameters:
sourceConn -
ti -
column -
Returns:
Throws:
SQLException

getColumnNames

public static String[] getColumnNames(ISQLConnection sourceConn,
                                      ITableInfo ti)
                               throws SQLException
Parameters:
sourceConn -
ti -
Returns:
Throws:
SQLException

getSelectQuery

public static String getSelectQuery(SessionInfoProvider prov,
                                    String columnList,
                                    ITableInfo ti)
                             throws SQLException,
                                    UserCancelledOperationException
Parameters:
columnList -
ti -
Returns:
Throws:
SQLException
UserCancelledOperationException

isBinaryType

public static boolean isBinaryType(TableColumnInfo columnInfo)
Returns a boolean value indicating whether or not the specified TableColumnInfo represents a database column that holds binary type data.

Parameters:
columnInfo - the TableColumnInfo to examine
Returns:
true if binary; false otherwise.

getQualifiedObjectName

public static String getQualifiedObjectName(ISession session,
                                            String catalogName,
                                            String schemaName,
                                            String objectName,
                                            int sessionType)
                                     throws UserCancelledOperationException
Decide whether or not the session specified needs fully qualified table names (schema.table). In most databases this is optional (Oracle). In others it is required (Progress). In still others it must not occur. (Axion, Hypersonic)

Parameters:
session -
catalogName -
schemaName -
objectName -
Returns:
Throws:
UserCancelledOperationException

getCatSep

public static String getCatSep(ISession session)

fixCase

public static String fixCase(ISession session,
                             String identifier)
Uppercase / Lowercase / Mixedcase identifiers are a big problem. Some databases support mixing case (like McKoi) others force identifier case to all uppercase or all lowercase. Some (like MySQL) can be configured to care or not care about case as well as depending on the platform the database is on. This method attempt to use the metadata from the driver to "fix" the case of the identifier to be acceptable for the specified session.

Parameters:
session - the session whose disposition on case we care about.
identifier -
Returns:

getColumnCount

public static int getColumnCount(ISQLConnection sourceConn,
                                 ITableInfo ti)
                          throws SQLException
Parameters:
sourceConn -
ti -
Returns:
Throws:
SQLException

getColumnType

public static int getColumnType(ISQLConnection con,
                                ITableInfo ti,
                                int column)
                         throws SQLException
Parameters:
con -
ti -
column -
Returns:
Throws:
SQLException

getColumnTypes

public static int[] getColumnTypes(ISQLConnection con,
                                   ITableInfo ti)
                            throws SQLException
Throws:
SQLException

sameDatabaseType

public static boolean sameDatabaseType(ISession session1,
                                       ISession session2)

getMaxColumnLengthSQL

public static String getMaxColumnLengthSQL(ISession sourceSession,
                                           TableColumnInfo colInfo,
                                           String tableName,
                                           boolean tableNameIsQualified)
                                    throws UserCancelledOperationException
Gets the SQL statement which can be used to select the maximum length of the current data found in tableName within the specified column.

Parameters:
sourceSession -
colInfo -
tableName -
tableNameIsQualified - whether or not the specified tableName is qualified.
Returns:
Throws:
UserCancelledOperationException

setLastStatement

public static void setLastStatement(String lastStatement)
Parameters:
lastStatement - the lastStatement to set

getLastStatement

public static String getLastStatement()
Returns:
the lastStatement

setLastStatementValues

public static void setLastStatementValues(String values)

getLastStatementValues

public static String getLastStatementValues()


Copyright © 2001-2010. All Rights Reserved.