| java.lang.Object net.sourceforge.squirrel_sql.plugins.dbcopy.I18NBaseObject net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil
DBUtil | public class DBUtil extends I18NBaseObject (Code) | | A utility class for interacting with the database.
|
Method Summary | |
public static String | bindVariable(PreparedStatement ps, int sourceColType, int destColType, int index, ResultSet rs) Reads the value from the specified ResultSet at column index index, and
based on the type, calls the appropriate setXXX method on ps with the
value obtained. | public static void | checkKeyword(ISession session, String table, String column) Checks the specified column is not a keyword in the specified session. | public static void | deleteDataInExistingTable(ISession session, String catalogName, String schemaName, String tableName) Deletes existing data from the destination connection specified in the
specified table. | public static boolean | dropTable(String tableName, String schemaName, String catalogName, ISession session, boolean cascade, int sessionType) | public static ResultSet | executeQuery(ISession session, String sql) Executes the specified sql statement on the specified connection and
returns the ResultSet.
Parameters: con - Parameters: sql - Parameters: mysqlBigResultFix - if true, provides a work-around which is usefulin the case that the connection is to a MySQL database. | public static int | executeUpdate(ISQLConnection con, String SQL, boolean writeSQL) Executes the given SQL using the specified SQLConnection.
Parameters: con - the SQLConnection to execute the update on. Parameters: SQL - the statement to execute. | public static String | fixCase(ISession session, String identifier) Uppercase / Lowercase / Mixedcase identifiers are a big problem. | public static String | getCatSep(ISession session) | public static int | getColumnCount(ISQLConnection sourceConn, ITableInfo ti) | public static String | getColumnList(TableColumnInfo[] colInfoArr) | public static String | getColumnName(ISQLConnection sourceConn, ITableInfo ti, int column) | public static String[] | getColumnNames(ISQLConnection sourceConn, ITableInfo ti) | public static String | getColumnSql(SessionInfoProvider prov, TableColumnInfo colInfo, String sourceTableName, String destTableName) Uses the column type mapper to get the column type and appends that to the
name with an optional not null modifier. | public static int | getColumnType(ISQLConnection con, ITableInfo ti, String columnName) | public static int | getColumnType(ISQLConnection con, ITableInfo ti, int column) | public static int[] | getColumnTypes(ISQLConnection con, ITableInfo ti, String[] colNames) | public static int[] | getColumnTypes(ISQLConnection con, ITableInfo ti) | public static String | getCreateTableSql(SessionInfoProvider prov, ITableInfo ti) | public static Set<String> | getForeignKeySQL(SessionInfoProvider prov, ITableInfo ti, ArrayList<ITableInfo> selectedTableInfos) Returns a List of SQL statements that add foreign key(s) to the table
described in the specified ITableInfo. | public static String | getInsertSQL(SessionInfoProvider prov, String columnList, ITableInfo ti, int columnCount) | public static String | getLastStatement() | public static String | getLastStatementValues() | public 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. | public 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. | public 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). | public static String | getSelectQuery(SessionInfoProvider prov, String columnList, ITableInfo ti) | public static int | getTableCount(ISession session, String catalog, String schema, String tableName, int sessionType) Returns a count of the records in the specified table. | public static ITableInfo | getTableInfo(ISession session, String schema, String tableName) | public static ITableInfo[] | getTables(ISession session, String catalog, String schema, String tableName) | 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. | public static boolean | isKeyword(ISession session, String data) Check the specified session to determine if the specified data is a
keyword. | public static int | replaceOtherDataType(TableColumnInfo colInfo) Takes the specified colInfo, gets the data type to see if it is
1111(OTHER). | public static boolean | sameDatabaseType(ISession session1, ISession session2) | public static void | sanityCheckPreferences(ISession destSession) This will take into account any special needs that the destination
session has with regard to user preferences, and throw a MappingException
if any user preference isn't valid for the specified destination session. | public static void | setLastStatement(String lastStatement) | public static void | setLastStatementValues(String values) | public static void | setPreferences(DBCopyPreferenceBean bean) | public static boolean | tableHasForeignKey(String destCatalog, String destSchema, String destTableName, ForeignKeyInfo fkInfo, SessionInfoProvider prov) | public static boolean | tableHasPrimaryKey(ISQLConnection con, ITableInfo ti) | public static boolean | typesAreEquivalent(int sourceType, int destType) Decides whether or not the specified column types
(java.sql.Type constants) use the same java type to read from the source
database as the one used to write to the destination database. | public static void | validateColumnNames(ITableInfo ti, SessionInfoProvider prov) |
bindVariable | public static String bindVariable(PreparedStatement ps, int sourceColType, int destColType, int index, ResultSet rs) throws SQLException(Code) | | Reads the value from the specified ResultSet at column index index, and
based on the type, calls the appropriate setXXX method on ps with the
value obtained.
Parameters: ps - Parameters: sourceColType - Parameters: destColType - Parameters: index - Parameters: rs - a string representation of the value that was bound. throws: SQLException - |
checkKeyword | public static void checkKeyword(ISession session, String table, String column) throws MappingException(Code) | | Checks the specified column is not a keyword in the specified session.
Parameters: session - the session whose keywords to check against Parameters: table - the name of the table to use in the error message Parameters: column - the name of the column to check throws: MappingException - if the specified column is a keyword in the specified session |
deleteDataInExistingTable | public static void deleteDataInExistingTable(ISession session, String catalogName, String schemaName, String tableName) throws SQLException, UserCancelledOperationException(Code) | | Deletes existing data from the destination connection specified in the
specified table. This will use preferences to determine if truncate
command is preferred. If truncate is preferred and fails, then delete
will be attempted.
Parameters: con - Parameters: tablename - throws: SQLException - |
executeQuery | public static ResultSet executeQuery(ISession session, String sql) throws SQLException(Code) | | Executes the specified sql statement on the specified connection and
returns the ResultSet.
Parameters: con - Parameters: sql - Parameters: mysqlBigResultFix - if true, provides a work-around which is usefulin the case that the connection is to a MySQL database. If the number of rows is large this will prevent the driver from readingthem all into client memory. MySQL's normal practice is to do such a thing for performance reasons. throws: Exception - |
executeUpdate | public static int executeUpdate(ISQLConnection con, String SQL, boolean writeSQL) throws SQLException(Code) | | Executes the given SQL using the specified SQLConnection.
Parameters: con - the SQLConnection to execute the update on. Parameters: SQL - the statement to execute. either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing throws: SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object |
fixCase | public static String fixCase(ISession session, String identifier)(Code) | | 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. Parameters: identifier - |
getLastStatement | public static String getLastStatement()(Code) | | the lastStatement |
getLastStatementValues | public static String getLastStatementValues()(Code) | | |
getMaxColumnLengthSQL | public static String getMaxColumnLengthSQL(ISession sourceSession, TableColumnInfo colInfo, String tableName, boolean tableNameIsQualified) throws UserCancelledOperationException(Code) | | 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 - Parameters: colInfo - Parameters: tableName - Parameters: tableNameIsQualified - TODO |
getPKColumnString | public static String getPKColumnString(ISQLConnection sourceConn, ITableInfo ti) throws SQLException(Code) | | 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 - Parameters: ti - throws: SQLException - |
getQualifiedObjectName | public static String getQualifiedObjectName(ISession session, String catalogName, String schemaName, String objectName, int sessionType)(Code) | | 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 - Parameters: catalogName - Parameters: schemaName - Parameters: objectName - throws: UserCancelledOperationException - |
getTableCount | public static int getTableCount(ISession session, String catalog, String schema, String tableName, int sessionType) throws UserCancelledOperationException(Code) | | Returns a count of the records in the specified table.
Parameters: con - the SQLConnection to use to execute the count query. Parameters: tableName - the name of the table -1 if the table does not exist, otherwise the record count isreturned. |
isBinaryType | public static boolean isBinaryType(TableColumnInfo columnInfo)(Code) | | 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 true if binary; false otherwise. |
isKeyword | public static boolean isKeyword(ISession session, String data)(Code) | | Check the specified session to determine if the specified data is a
keyword.
Parameters: session - Parameters: data - |
replaceOtherDataType | public static int replaceOtherDataType(TableColumnInfo colInfo) throws MappingException(Code) | | 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 - throws: MappingException - |
sanityCheckPreferences | public static void sanityCheckPreferences(ISession destSession) throws MappingException(Code) | | This will take into account any special needs that the destination
session has with regard to user preferences, and throw a MappingException
if any user preference isn't valid for the specified destination session.
Parameters: destSession - |
setLastStatement | public static void setLastStatement(String lastStatement)(Code) | | Parameters: lastStatement - the lastStatement to set |
setLastStatementValues | public static void setLastStatementValues(String values)(Code) | | |
typesAreEquivalent | public static boolean typesAreEquivalent(int sourceType, int destType)(Code) | | Decides whether or not the specified column types
(java.sql.Type constants) use the same java type to read from the source
database as the one used to write to the destination database. For
example, Types.DECIMAL and Types.NUMERIC both use BigDecimal java type
to store the value in between reading and writing it. Therefore, even
though these types are not equal, they are equivalent. This method has
not yet been fully implemented with equivalences from the bindVariable
method.
Parameters: sourceType - the column type as identified by the source databasejdbc driver. Parameters: destType - the column type as identified by the destination databasejdbc driver. true if equivalent, false if not. |
|
|