public class DatabaseUtilities extends Object
Modifier and Type | Method and Description |
---|---|
static void |
addColumnIfNecessary(IfsConnection conn,
String tableName,
String columnName,
String rdbmsDataType)
Alter the specified table to add a new column.
|
static void |
analyze(IfsConnection conn,
String schemaName)
Analyze a schema.
|
static void |
analyzeTable(IfsConnection conn,
String schemaName,
String tableName)
Analyze a table in a schema.
|
static void |
analyzeTable(LibrarySession session,
String tableName)
Analyze a single table in the IFS schema.
|
static void |
closeResultSet(ResultSet rset)
Close a ResultSet, ignoring any Exceptions.
|
static void |
closeStatement(StatementWrapper stmt)
Close a StatementWrapper, ignoring any Exceptions.
|
static boolean |
columnExists(IfsConnection conn,
String tableName,
String columnName)
Return true if the specified column exists in the specified table.
|
static boolean |
columnExists(LibrarySession session,
String tableName,
String columnName)
Return true if the specified column exists in the specified table.
|
static void |
commit(IfsConnection conn)
Issue a commit.
|
static void |
createTable(IfsConnection conn,
String tableName,
String createStmt)
Create a table.
|
static void |
createTable(IfsConnection conn,
String tableName,
String createStmt,
boolean dropFirst)
Create a table, optionally attempting to drop the table first.
|
static void |
createTable(LibrarySession session,
String tableName,
String createStmt)
Create a table.
|
static void |
createTable(LibrarySession session,
String tableName,
String createStmt,
boolean dropFirst)
Create a table, optionally attempting to drop the table first.
|
static void |
dropTable(IfsConnection conn,
String tableName)
Drop a table.
|
static void |
dropTable(LibrarySession session,
String tableName)
Drop a table.
|
static void |
executeCall(LibrarySession session,
String sql)
Execute a PL/SQL call.
|
static void |
executeStatement(IfsConnection conn,
String stmtString)
Execute any SQL statement
|
static void |
executeStatement(LibrarySession session,
String stmtString)
Execute any SQL statement.
|
static int |
executeUpdate(IfsConnection conn,
String stmtString)
Execute an update statement.
|
static int |
executeUpdate(LibrarySession session,
String stmtString)
Execute an update, delete, or insert statement.
|
static String |
getColumnList(String[] cols)
Return the concatenation of the specified columns as a
comma-separated column list.
|
static String |
getUpdateSql(String tableName,
String[] pkCols,
String updateClause)
Return the SQL used to update row that can be identified uniquely.
|
static String |
getUpdateWhereClause(String[] cols)
Return the clause to use in the SQL update's where clause
to uniquely identify the row to be updated.
|
static boolean |
isValidConnection(IfsConnection conn)
Test validity of a IfsConnection
|
static void |
performAnalyze(LibrarySession session)
Perform ANALYZE on the IFS schema.
|
static void |
performAnalyzeOracle(LibrarySession session)
Execute the ANALYZE action for Oracle.
|
static void |
performAnalyzePostgres(LibrarySession session)
Execute the ANALYZE action for Postgres.
|
static void |
renameColumn(IfsConnection conn,
String tableName,
String columnName,
String newColumnName)
Alter the specified table to rename a column.
|
static void |
rollback(IfsConnection conn)
Issue a rollback.
|
static boolean |
rowExists(IfsConnection conn,
String tableName,
String condition)
Return true if there is a row that meets the specified condition
for the specified table.
|
static boolean |
rowExists(LibrarySession session,
String tableName,
String condition)
Return true if there is a row that meets the specified condition
for the specified table.
|
static int |
selectCount(IfsConnection conn,
String tableName,
String condition)
Selects the row count that meets the specified condition
for the specified table.
|
static int |
selectCount(LibrarySession session,
String tableName,
String condition)
Selects the row count that meets the specified condition
for the specified table.
|
static long |
selectMinOrMax(IfsConnection conn,
String selClause,
String tableName,
String condition)
Selects the min or max doc ID from the specified table.
|
static long |
selectMinOrMax(LibrarySession session,
String selClause,
String tableName,
String condition)
Selects the min or max doc ID from the specified table.
|
static boolean |
tableExists(IfsConnection conn,
String tableName)
Return true if the specified table exists.
|
static boolean |
tableExists(LibrarySession session,
String tableName)
Return true if the specified table exists.
|
public static void executeStatement(LibrarySession session, String stmtString) throws IfsException
session
- the session contextstmtString
- the SQL to executeIfsException
- if the operation failspublic static int executeUpdate(LibrarySession session, String stmtString) throws IfsException
Returns the number of rows affected by the update, delete, or insert.
session
- the session contextstmtString
- the SQL to executeIfsException
- if the operation failspublic static void executeCall(LibrarySession session, String sql) throws IfsException
session
- the session contextsession
- the SQL to execute in a CallableStatementIfsException
- if operation failspublic static void createTable(LibrarySession session, String tableName, String createStmt) throws IfsException
session
- the session contexttableName
- the name of the tablecreateStmt
- the CREATE TABLE sql stringIfsException
- if the operation failspublic static void createTable(LibrarySession session, String tableName, String createStmt, boolean dropFirst) throws IfsException
session
- the session contexttableName
- the name of the tablecreateStmt
- the CREATE TABLE sql stringdropFirst
- whether to attempt to drop the table firstIfsException
- if the operation failspublic static void dropTable(LibrarySession session, String tableName) throws IfsException
Does not throw an exception if the attempt fails.
session
- the session contexttableName
- the name of the tableIfsException
- if the operation failspublic static boolean rowExists(LibrarySession session, String tableName, String condition) throws IfsException
session
- the session contexttableName
- the table namecondition
- the where clauseIfsException
- if the operation failspublic static int selectCount(LibrarySession session, String tableName, String condition) throws IfsException
Throws if the table does not exist.
session
- the session contexttableName
- the table namecondition
- the where clauseIfsException
- if the operation failspublic static long selectMinOrMax(LibrarySession session, String selClause, String tableName, String condition) throws IfsException
session
- the session contextselClause
- the min or max clause to be selectedtableName
- the table namecondition
- the where clauseIfsException
- if the operation failspublic static void performAnalyze(LibrarySession session) throws IfsException
session
- the session contextIfsException
- if operation failspublic static void performAnalyzeOracle(LibrarySession session) throws IfsException
session
- the session contextIfsException
- if operation failspublic static void performAnalyzePostgres(LibrarySession session) throws IfsException
session
- the session contextIfsException
- if operation failspublic static void analyzeTable(LibrarySession session, String tableName) throws IfsException
This is currently only supported on Oracle.
session
- the session contexttableName
- the name of the table to analyzeIfsException
- if the operation failspublic static boolean tableExists(LibrarySession session, String tableName) throws IfsException
session
- the session contexttableName
- the table nameIfsException
- if the operation failspublic static boolean columnExists(LibrarySession session, String tableName, String columnName) throws IfsException
session
- the session contexttableName
- the table namecolumnName
- the column nameIfsException
- if the operation failspublic static void executeStatement(IfsConnection conn, String stmtString) throws SQLException
conn
- the database connectionstmtString
- the SQL to executeSQLException
- if the operation failspublic static int executeUpdate(IfsConnection conn, String stmtString) throws SQLException
Returns the number of rows affected by the update.
conn
- the database connectionstmtString
- the SQL to executeSQLException
- if the operation failspublic static void createTable(IfsConnection conn, String tableName, String createStmt) throws SQLException
conn
- the database connectiontableName
- the name of the tablecreateStmt
- the CREATE TABLE sql stringSQLException
- if the operation failspublic static void createTable(IfsConnection conn, String tableName, String createStmt, boolean dropFirst) throws SQLException
conn
- the database connectiontableName
- the name of the tablecreateStmt
- the CREATE TABLE sql stringdropFirst
- whether to attempt to drop the table firstSQLException
- if the operation failspublic static void dropTable(IfsConnection conn, String tableName) throws SQLException
Does not throw an exception if the attempt fails.
conn
- the database connectiontableName
- the name of the tableSQLException
- if the operation failspublic static boolean rowExists(IfsConnection conn, String tableName, String condition) throws SQLException
conn
- the database connectiontableName
- the table namecondition
- the where clauseSQLException
- if the operation failspublic static int selectCount(IfsConnection conn, String tableName, String condition) throws SQLException
Throws if the table does not exist.
conn
- the database connectiontableName
- the table namecondition
- the where clauseSQLException
- if the operation failspublic static long selectMinOrMax(IfsConnection conn, String selClause, String tableName, String condition) throws SQLException
conn
- the database connectionselClause
- the min or max clause to be selectedtableName
- the table namecondition
- the where clauseSQLException
- if the operation failspublic static boolean tableExists(IfsConnection conn, String tableName) throws SQLException
conn
- the database connectiontableName
- the table nameSQLException
- if the operation failspublic static boolean columnExists(IfsConnection conn, String tableName, String columnName) throws SQLException
conn
- the database connectiontableName
- the table namecolumnName
- the column nameSQLException
- if the operation failspublic static void addColumnIfNecessary(IfsConnection conn, String tableName, String columnName, String rdbmsDataType) throws SQLException
conn
- database connectiontableName
- the table namecolumnName
- the name of the new column to addrdbmsDataType
- the DBMS data type string (e.g. "NUMBER(20)" )SQLException
- if the operation failspublic static void renameColumn(IfsConnection conn, String tableName, String columnName, String newColumnName) throws SQLException
conn
- database connectiontableName
- the table namecolumnName
- the name of the existing columnnewColumnName
- the new name for the columnSQLException
- if the operation failspublic static void analyze(IfsConnection conn, String schemaName) throws SQLException
conn
- the database connectionschemaName
- the name of the schema to analyzeSQLException
- if the operation failspublic static void analyzeTable(IfsConnection conn, String schemaName, String tableName) throws SQLException
conn
- the database connectionschemaName
- the name of the schema containing the tabletableName
- the name of the table to analyzeSQLException
- if the operation failspublic static void commit(IfsConnection conn) throws SQLException
conn
- the database connectionSQLException
- if the operation failspublic static void rollback(IfsConnection conn) throws SQLException
conn
- the database connectionSQLException
- if the operation failspublic static String getColumnList(String[] cols)
cols
- the columnspublic static String getUpdateWhereClause(String[] cols)
Returns a String like: "COLX = ? and COLY = ? and COLZ = ?"
pkCols
- the column namespublic static String getUpdateSql(String tableName, String[] pkCols, String updateClause)
Returns a String like: UPDATE tablename x set NEWCOLa = 0, NEWCOLb = 0 where PKCOL1 = ? and PKCOL2 = ?
tableName
- the table namepkCols
- the primary key columnsupdColClause
- the update clause list; e.g. "NEWCOLa = 0, NEWCOLb = 0"public static boolean isValidConnection(IfsConnection conn)
conn
- the database connectionpublic static void closeResultSet(ResultSet rset)
rset
- the ResultSet to closepublic static void closeStatement(StatementWrapper stmt)
stmt
- the statement to closeCopyright © 2023. All rights reserved.