public abstract class AbstractWorkTask extends Object implements IWorkTask
Constructor and Description |
---|
AbstractWorkTask() |
Modifier and Type | Method and Description |
---|---|
protected static void |
assignCell(PreparedStatement stmt,
int n,
IColumn type,
String val)
Assigning cell for SQL Batch operation.
|
protected static void |
executeBatch(Connection conn,
IColumn[] columns,
List<String> updcols,
List<String[]> rows,
String cmd,
IColumn[] index,
String[][] where)
Executing SQL statement using batch mode.
|
void |
finish(IContext context,
String indentation) |
IColumn[] |
getAllColumns()
All columns in table.
|
IColumn[] |
getColumns()
Gets an array of columns necessary to read from the table.
|
String |
getDescription()
Get description of the task.
|
String |
getWhere()
Where clause as a string.
|
protected static String |
getWhere(String where,
String[] parameters)
Substitute parameters in WHERE clause.
|
protected abstract void |
initCols(Collection<IColumn> cols)
Abstract method to assemble list of columns necessary.
|
protected void |
prepareInputs(IContext context,
IAnonymization[] anonymizations)
Prepare inputs that are based on current values.
|
protected static void |
registerAnonymizations(Collection<IColumn> cols,
IAnonymization[] anos)
Utility method to register anonymization methods and if necessary add the column to the list.
|
static String |
schemaPrefix(String table)
Adds schema prefix to table if necessary.
|
void |
setLogPrefix(String prefix)
Set the prefix for log messages.
|
static boolean |
sql(IContext context,
String sql)
Executes the given SQL statement
|
protected static String |
sqlColumnsWrap(Collection<String> columns) |
protected int |
sqlCountRows(Connection conn)
Count rows.
|
protected static void |
sqlExecuteUpdate(Connection conn,
String cmd) |
protected void |
sqlInsertRows(Connection conn,
List<String> updatecolumns,
List<String[]> rows)
Inserts rows with a list of updatecolumns.
|
protected static List<String[]> |
sqlReadRows(Connection conn,
String table,
List<String> columns,
String where)
Reads rows with a list of columns from table using specified where clause.
|
protected void |
sqlUpdateRows(Connection conn,
List<String> updatecolumns,
List<String[]> rows,
String[][] where)
Updates rows with a list of columns from table using specified where clause.
|
protected static void |
sqlUpdateRows(Connection conn,
String table,
List<IColumn> columns,
Collection<String> updatecolumns,
List<String[]> rows,
String where)
Updates rows from a list of columns from table using specified where clause.
|
protected void |
sqlUpdateRowsNoIndex(Connection conn,
IColumn[] columns,
List<String> updatecolumns,
List<String[]> rows)
Updates rows with a list of columns from table using specified where clause.
|
void |
start(IContext context,
String indentation) |
static String |
wrap(String name)
Wraps/qutoes in " " if it contains spaces.
|
protected String prefix
public void setLogPrefix(String prefix)
ITask
setLogPrefix
in interface ITask
prefix
- Log message prefixpublic String getWhere()
IWorkTask
public IColumn[] getAllColumns()
IWorkTask
getAllColumns
in interface IWorkTask
public String getDescription()
ITask
getDescription
in interface ITask
public IColumn[] getColumns()
protected abstract void initCols(Collection<IColumn> cols)
cols
- list of column definitionsprotected static void registerAnonymizations(Collection<IColumn> cols, IAnonymization[] anos)
cols
- columnsanos
- anonymizationspublic static String schemaPrefix(String table) throws IOException
table
- nameIOException
- when problems reading config filepublic static String wrap(String name)
name
- schema/table/column name to be wrappedprotected int sqlCountRows(Connection conn) throws IOException
conn
- ConnectionIOException
- when problems reading config fileprotected static List<String[]> sqlReadRows(Connection conn, String table, List<String> columns, String where) throws SQLException, IOException
conn
- connectiontable
- namecolumns
- list of column nameswhere
- string - can be nullSQLException
- when SQL issuesIOException
- when problems reading config fileprotected static String sqlColumnsWrap(Collection<String> columns)
protected static void sqlUpdateRows(Connection conn, String table, List<IColumn> columns, Collection<String> updatecolumns, List<String[]> rows, String where) throws IOException, SQLException
conn
- Connectiontable
- namecolumns
- list of column namesupdatecolumns
- columns to be updatedrows
- data rowswhere
- string clauseSQLException
- when SQL issuesIOException
- when problems reading config fileprotected void sqlUpdateRows(Connection conn, List<String> updatecolumns, List<String[]> rows, String[][] where) throws IOException, SQLException
conn
- Connectionupdatecolumns
- list of namesrows
- data to updatewhere
- Array of [index-column,rows]SQLException
- when SQL issuesIOException
- when problems reading config fileprotected void sqlUpdateRowsNoIndex(Connection conn, IColumn[] columns, List<String> updatecolumns, List<String[]> rows) throws IOException, SQLException
conn
- Connectioncolumns
- column definitionsupdatecolumns
- list of namesrows
- data to updateSQLException
- when SQL issuesIOException
- when problems reading config fileprotected void sqlInsertRows(Connection conn, List<String> updatecolumns, List<String[]> rows) throws IOException, SQLException
conn
- Connectionupdatecolumns
- list of namesrows
- of dataSQLException
- when SQL issuesIOException
- when problems reading config fileprotected static void executeBatch(Connection conn, IColumn[] columns, List<String> updcols, List<String[]> rows, String cmd, IColumn[] index, String[][] where) throws SQLException
conn
- Connectioncolumns
- Columnsupdcols
- list of names of colums to be updatedrows
- of datacmd
- SQL command lineindex
- array of index columnswhere
- string clauseSQLException
- SQL errorprotected static void assignCell(PreparedStatement stmt, int n, IColumn type, String val) throws SQLException
stmt
- prepared statementn
- cell numbertype
- column typeval
- value to assignSQLException
- if there's error in JDBC operationprotected static void sqlExecuteUpdate(Connection conn, String cmd) throws SQLException
SQLException
protected void prepareInputs(IContext context, IAnonymization[] anonymizations) throws Throwable
context
- contains Connectionanonymizations
- array of anonymizationsSQLException
- SQL errorThrowable
protected static String getWhere(String where, String[] parameters)
where
- clauseparameters
- array of stringspublic static boolean sql(IContext context, String sql) throws SQLException, Throwable
context
- Context containing connectionsql
- SQL statementSQLException
- SQL ExceptionThrowable
- Driver exceptionsCopyright © 2021. All rights reserved.