|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.sql.ConnectionHelper
public class ConnectionHelper
The class JDBC provides several useful methods for handling JDBC connections. Note that this class is not synchronized, i.e. the methods can work simultaneously on one shared Connection instance.
JDBCTableModel,
SQLConstraint,
SQLMapFilter,
DefaultMappingInfo.getNameForType(int)| Constructor Summary | |
|---|---|
ConnectionHelper(Connection con)
|
|
| Method Summary | ||
|---|---|---|
void |
addIndex(String table,
String indexName,
boolean unique,
String... columns)
|
|
void |
addOrderBy(Appendable q,
String... orderByColumns)
the given columns are used to append an 'order by' statement; if a column is preceded by a '-' sign, it will be converted to a descending sorting order Note that the columns must already be 'escaped' if required. |
|
void |
addPrimaryIndex(String table,
String... columns)
|
|
void |
addWhereClause(Appendable sql,
List<Object> parameters,
Map<String,?> restrictions)
calls addWhereClause(sql, parameters, restrictions, true) |
|
void |
addWhereClause(Appendable sql,
List<Object> parameters,
Map<String,?> restrictions,
boolean combineWithAndIfTrue)
takes a given query, a given list of parameters (for binding the query to a PreparedStatement), a map of restrictions and processes the map so that it will be put into the query and the parameters. |
|
void |
addWhereClause(Appendable sql,
List<Object> parameters,
String[] textColumns,
String... patternList)
constructs a where-clause for a larger SQL-statement that searches for the given pattern in the given text columns |
|
void |
addWhereClauseOnSearchPattern(String[] patternList,
Appendable sb,
List<Object> params,
Map<String,Integer> map,
String... columnNames)
allows to add full text search in all columns to an existing query; every pattern must be found in some column |
|
void |
addWhereClauseOnSearchPattern(String[] patternList,
Appendable sb,
List<Object> params,
String table)
allows to add full text search in all columns to an existing query; every pattern must be found in some column |
|
boolean |
contains(RowItem row)
checks to see whether the given row can be found in this connection (based on the table and the id) |
|
boolean |
contains(String tableName,
String columnName,
Object value)
|
|
static Range<Date> |
convertDateRangeToSQL(Range<Date> range)
utility function to ease of use |
|
static Range<Timestamp> |
convertTimestampRangeToSQL(Range<Date> range)
utility function to ease of use |
|
int |
copyIndices(String sourceTable,
Connection target,
String targetTable)
returns the number of indices that were actually created; existing index names as well as 'primary' keys are skipped |
|
boolean |
copyPrimaryKey(String sourceTable,
Connection target,
String targetTable)
|
|
void |
copyTable(String sourceTable,
Connection target,
String targetTable,
boolean createTable)
creates a new table in Connection target corresponding to
the given table in this Connection and transfers all data |
|
void |
copyTable(String sourceTable,
Connection target,
String targetTable,
boolean createTable,
Monitor mon)
creates a new table in Connection target corresponding to
the given table in this Connection and transfers all data |
|
void |
copyTo(Connection target,
boolean createTables)
copies all tables from one connection into the other connection |
|
int |
countDistinctValues(String table,
String columnField,
Map<String,?> restrictions)
|
|
String |
createTableString(ResultSetMetaData data,
String tableName)
creates the DDL statement that would create a table identical to the one denoted by the given meta data |
|
void |
delete(RowItem row)
|
|
int |
deleteRow(String tableName,
String columnField,
Object columnValue)
deletes all rows in the given table where the given field equals the given value |
|
int |
deleteRows(String tableName,
Map<String,?> fieldRestrictions)
the fieldRestrictions support Range, LikeCondition, NotNullCondition, IsNullCondition objects and Object[] as values |
|
void |
dropIndex(String table,
String index)
|
|
String |
escape(String columnOrTableName)
escapes column and/or table names. |
|
String[] |
escape(String[] columnNames)
|
|
int |
executeUpdate(String sql,
Object... params)
shortcut to perform an update via SQL statement |
|
void |
exportAsCSV(File file,
Monitor mon,
String sql,
Object... params)
|
|
void |
exportAsCSV(ResultSet rs,
Writer writer,
Monitor mon)
|
|
void |
exportAsCSV(ResultSet rs,
Writer writer,
Monitor mon,
boolean useQuotes,
String fieldSeparator,
String recordSeparator,
boolean includeHeader)
streams the given ResultSet to the given Writer; note that neither resource is closed within this call! |
|
void |
exportAsCSV(Writer writer,
Monitor mon,
String sql,
Object... params)
|
|
HashMap<String,Object> |
extractRow(ResultSet rs,
String... columns)
extracts the current row in the given ResultSet into a HashMap; if no columns are given, all columns will be included. |
|
RowItem |
extractRowItem(ResultSet rs,
String idColumnName,
String... columns)
if no further column names are given, all columns will be included |
|
ArrayList<HashMap<String,Object>> |
extractRows(ResultSet rs,
String... columns)
returns a map per row, where column names are mapped to their respective value. |
|
ResultSet |
filterTable(String tableName,
Map<String,?> fieldRestrictions)
returns all columns (*) that correspond to the given restrictions, where each key is tested to be equal to the value. |
|
ResultSet |
filterTable(String tableName,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue)
returns all columns (*) that correspond to the given restrictions, where each key is tested to be equal to the value. |
|
ResultSet |
filterTable(String tableName,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
calls filterTable(String, String[], Map, boolean, int, int, String...) |
|
ResultSet |
filterTable(String tableName,
Map<String,?> fieldRestrictions,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
calls filterTable(tableName, fieldRestrictions, true, resultSetType, resultSetConcurrency, orderByColumns) |
|
ResultSet |
filterTable(String tableName,
String[] columns,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
allows to easily filter a table or query After being done w/ the ResultSet, it should be closed along w/ the corresponding statement. |
|
ResultSet |
filterTable(String tableName,
String columnName,
Object value)
|
|
ResultSet |
filterTableForText(int resultSetType,
int resultSetConcurrency,
String table,
String[] patternList,
String... restrictToColumn)
|
|
ResultSet |
filterTableForText(String table,
String... patternList)
in order to be in the result table, every given pattern must occur somewhere in a column |
|
ResultSet |
filterTableForText(String table,
String[] patternList,
String... restrictToColumn)
|
|
ResultSet |
filterTableScrollable(String tableName,
Map<String,?> fieldRestrictions)
returns all columns (*) that correspond to the given restrictions, where each key is tested to be equal to the value. |
|
ResultSet |
filterTableUpdateable(String tableName,
Map<String,?> fieldRestrictions)
returns an updateable and scrollable ResultSet. |
|
Map<Object,Integer> |
findDuplicates(String table,
Map<String,?> restrictions,
String... column)
|
|
ArrayList<RowItem> |
findInTable(String tableName,
String idColumn,
String pattern,
Monitor mon)
|
|
Object |
getAggregatedFunctionValue(String table,
String column,
SQLFunction function,
String method,
Map<String,?> fieldRestrictions)
|
|
Object |
getAggregatedFunctionValue(String table,
String column,
String function,
String method,
Map<String,?> fieldRestrictions)
returns the value of the given method on the given field in the given table based on the given function; null is returned if no entries were found in the database. |
|
Object |
getAverageValue(String table,
String columnField)
|
|
ArrayList<String> |
getColumnNames(String table)
|
|
String[] |
getCommonColumns(String... tables)
|
|
Connection |
getConnection()
|
|
int |
getCount(String table)
|
|
int |
getCount(String table,
Map<String,?> fieldRestrictions)
|
|
DateFormat |
getDateFormat()
if non-null, this format is used to convert between String and Date |
|
String |
getDBType()
|
|
HashSet<Object> |
getDistinctValues(String table,
String columnField)
returns all distinct values of the given column from the given table based on a group by statement. |
|
HashSet<Object> |
getDistinctValues(String table,
String columnField,
Map<String,?> fieldRestrictions)
returns all distinct values of the given column from the given table based on a group by statement. |
|
HashMap<Object,Integer> |
getDistinctValuesWithCount(String table,
Map<String,?> fieldRestrictions,
Filter<Integer> numberFilter,
String... columnField)
returns all distinct values of the given column from the given table with their count based on a group by statement. |
|
HashMap<Object,Integer> |
getDistinctValuesWithCount(String table,
Map<String,?> fieldRestrictions,
String... columnField)
returns all distinct values of the given column from the given table with their count based on a group by statement. |
|
int |
getFetchSize()
if other than 0 it is applied to the filter.. methods |
|
protected ResultSet |
getFirstRowFor(Statement stmt,
String tableNameOrQueryString)
first tries the 'top' syntax and then the 'limit' syntax to provide the result; if all fails, the complete ResultSet is produced. |
|
TableModelWrapper |
getForeignKeysModel(String table)
|
|
HashMap<String,SimpleEntry<String,String>> |
getForeingKeys(String table)
|
|
Object |
getFunctionValue(String table,
String columnField,
SQLFunction func)
|
|
Object |
getFunctionValue(String table,
String columnField,
SQLFunction function,
Map<String,?> fieldRestrictions)
|
|
Object |
getFunctionValue(String table,
String columnField,
String function)
|
|
Object |
getFunctionValue(String table,
String columnField,
String function,
Map<String,?> fieldRestrictions)
returns the value of the given field in the given table based on the given function; null is returned if no entries were found in the database. |
|
Map<String,List<String>> |
getIndicesForTable(String table,
boolean uniqueOnly)
|
|
int |
getMaxTextLength(String table,
String textColumn,
Map<String,?> restrictions)
|
|
Object |
getMaxValue(String table,
String columnField)
|
|
DefaultTableModel |
getMetaDataAsTableModel(String tableName)
Deprecated. |
|
Object |
getMinValue(String table,
String columnField)
|
|
String[] |
getPrimaryKeysForTable(String table)
returns the column names of the primary key(s) for the given table. |
|
Set<String> |
getReservedWords()
returns all reserved words including keywords, string and system functions |
|
ResultSet |
getResultSet(int resultSetType,
int resultSetConcurrency,
String sql,
Object... params)
allows to quickly generate the ResultSet for a query |
|
ResultSet |
getResultSet(String sql,
Object... params)
uses ResultSet.TYPE_FORWARD_ONLY and
ResultSet.CONCUR_READ_ONLY |
|
HashMap<String,Object> |
getRow(String tableName,
String idField,
Object idValue)
may return null if no row was found; returns the first occurrence if multiple rows exist |
|
RowItem |
getRowItem(String tableName,
String idField,
Object idValue)
may return null if no row was found; returns the first occurrence if multiple rows exist; null is not allowed as an idValue. |
|
ArrayList<RowItem> |
getRowItems(ResultSet rs,
String idField,
Filter<? super RowItem> filter)
filter may be null; the table name is obtained from the idField column |
|
ArrayList<RowItem> |
getRowItems(String tableName,
ResultSet rs,
String idField,
Filter<? super RowItem> filter)
allows to specify a tableName explicitly for the returned RowItem objects Note that the given ResultSet must still be closed after calling this method! |
|
ArrayList<RowItem> |
getRowItems(String tableName,
String idField)
|
|
ArrayList<RowItem> |
getRowItems(String tableName,
String idField,
Filter<? super RowItem> filter)
filter may be null |
|
ArrayList<RowItem> |
getRowItems(String tableName,
String idField,
Map<String,?> fieldRestrictions)
supports Range objects in the fieldRestrictions |
|
Object |
getSumValue(String table,
String columnField)
|
|
ArrayList<HashMap<String,Object>> |
getTable(String tableName)
retrieves the entire table and returns it as a list of maps containing the field names mapped to their respective values |
|
ResultSetTableModel |
getTableModel(String tableName,
String idColumnName,
Map<String,?> fieldRestrictions)
returns a table model based on the table filtered by the given restrictions |
|
String[] |
getTableNames()
|
|
static String |
getTypeNameFor(int type)
returns the declared field name for the given Types value |
|
Object |
getValue(String tableName,
String idColumn,
Object idValue,
String valueColumn)
a simplified way to retrieve the value of a column by querying the table based on a candidate key |
|
String[] |
getViews()
|
|
void |
importTableModel(String table,
TableModel model)
|
|
void |
insert(RowItem row)
|
|
int |
insertRow(String tableName,
Map<String,?> fieldValues)
|
|
int |
insertRow(String tableName,
Map<String,?> fieldValues,
boolean ignoreInvalidColumns)
inserts the given field values as a row into the given table of the given connection. |
|
int |
insertRow(String tableName,
Object... values)
inserts the given values as a single row into the given table of the given connection. |
|
int |
insertRowWithGeneratedKeys(String tableName,
Map<String,?> fieldValues)
inserts the given field values as a row into the given table of the given connection and returns the generated key |
|
int |
insertTableModel(String tableName,
TableModel model,
boolean batchMode)
the table model is inserted based on the column order rather than column names. |
|
static boolean |
isCharType(int sqlType)
returns true only if the given sqlType is for characters |
|
static boolean |
isDateType(int sqlType)
returns true only if the given sqlType is for date/time |
|
boolean |
isMSAccess()
|
|
boolean |
isMySQL()
|
|
static boolean |
isNumberType(int sqlType)
returns true only if the given sqlType is for numbers |
|
static boolean |
isSelect(String name)
true only if the given string starts with 'select ' |
|
boolean |
isSQLServer()
|
|
AbstractIterator<Map<String,Object>> |
iterate(ResultSet rs)
remove() and close() are properly implemented in the returned iterator |
|
Object |
javaToSql(Object obj,
int sqlType,
int size)
supports a few standard types to ease translations between java and sql types. |
|
HashMap<Object,Object> |
loadAsMap(String table,
String keyColumn,
String valueColumn,
Map<String,?> restrictions)
|
|
TableModelWrapper |
loadTable(ResultSet rs,
boolean closeAfterUse)
allows to load a table for ResultSets that only support ResultSet.TYPE_FORWARD_ONLY |
|
TableModelWrapper |
loadTable(String table)
|
|
void |
lockTable(boolean exclusive,
String... tables)
useful for early requiring locks to avoid deadlocks |
|
Hashtable<String,String> |
mapColumnNamesToDisplayNames(String tableNameOrQueryString)
creates a special map to retrieve the label names from the column names as provided from the meta data |
|
Hashtable<String,Integer> |
mapColumnNamesToSize(ResultSet rs)
|
|
Hashtable<String,Integer> |
mapColumnNamesToSize(ResultSetMetaData meta)
|
|
Hashtable<String,Integer> |
mapColumnNamesToSize(String tableNameOrQueryString)
|
|
Hashtable<String,Integer> |
mapColumnNamesToSQLTypes(ResultSetMetaData meta)
|
|
Hashtable<String,Integer> |
mapColumnNamesToSQLTypes(String tableNameOrQueryString)
creates a special map to retrieve the SQL data types from the column names as provided from the meta data of the connection |
|
Hashtable<String,String> |
mapColumnNamesToTypeString(ResultSetMetaData meta)
|
|
Hashtable<String,String> |
mapColumnNamesToTypeString(String tableNameOrQueryString)
|
|
boolean |
needsSelect(String name)
|
|
void |
processColumn(String table,
String column,
Processor<Object,?> processor,
Map<String,?> restrictions)
|
|
ResultSet |
queryDuplicates(String table,
String... duplicateColumns)
finds records where the given columns appear more than once with their respective values |
|
int |
replace(String table,
String column,
Object oldValue,
Object newValue)
|
|
void |
searchDatabaseFor(String text,
PrintStream ps,
Monitor monitor)
searches through the entire database for the given text anywhere in any column and prints hints into the given stream. |
|
AbstractIterator<Object> |
searchDuplicates(String table,
String column,
Map<String,?> restrictions)
|
|
void |
setDateFormat(DateFormat dateFormat)
|
|
void |
setDoNotEscapeNames()
|
|
void |
setEscapeChars(char beginQuote,
char endQuote)
allows to explicitly set the escape chars used in escape(String)
, so that the default mechanism does not need to determine the chars by
accessing the meta data of the connection |
|
void |
setFetchSize(int fetchSize)
Note that for MySQL you want to use Integer.MIN_VALUE if you do
not want to load the entire ResultSet into memory |
|
|
sqlToJava(Object obj,
Class<T> requiredJavaType)
supports a few standard types to ease translations between sql and java types |
|
int |
transferTable(String sourceTable,
Connection target,
String targetTable,
Monitor mon,
Map<String,?> restrictions)
|
|
String |
trimToLastDot(String name)
|
|
Connection |
unwrap()
returns the embedded instance that this wrapper encloses |
|
void |
update(RowItem row)
|
|
int |
update(String table,
String column,
Object newValue,
Map<String,?> restrictions)
|
|
int |
update(String table,
String idColumn,
Object idValue,
String valueColumn,
Object newValue)
|
|
|
updateRows(Processor<ResultSet,T> updater,
String table,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
Monitor mon)
|
|
int |
updateRows(String tableName,
String idField,
Object idValue,
Map<String,?> fieldValues)
updates the rows in the given table by applying all of the given field values. |
|
int |
updateRows(String tableName,
String idField,
Object idValue,
Map<String,?> fieldValues,
boolean ignoreInvalidColumns)
updates all rows in the given table corresponding to the idValue by applying the given field values. |
|
void |
updateTable(String table,
String idColumn,
TableModel model)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ConnectionHelper(Connection con)
| Method Detail |
|---|
public int getFetchSize()
setFetchSize(int)public void setFetchSize(int fetchSize)
Integer.MIN_VALUE if you do
not want to load the entire ResultSet into memory
public Connection getConnection()
public final Connection unwrap()
Wrapped
unwrap in interface Wrapped<Connection>public String getDBType()
public boolean isMySQL()
public boolean isSQLServer()
public boolean isMSAccess()
public void setEscapeChars(char beginQuote,
char endQuote)
escape(String)
, so that the default mechanism does not need to determine the chars by
accessing the meta data of the connection
escape(String)public void setDoNotEscapeNames()
public String escape(String columnOrTableName)
setEscapeChars(char, char)public String[] escape(String[] columnNames)
@Todo(value="currently, this implementation does nothing")
public void lockTable(boolean exclusive,
String... tables)
throws SQLException
SQLExceptionpublic static String getTypeNameFor(int type)
Types value
public boolean needsSelect(String name)
public static boolean isSelect(String name)
public Set<String> getReservedWords()
throws SQLException
SQLException
public String[] getPrimaryKeysForTable(String table)
throws SQLException
SQLException
public Map<String,List<String>> getIndicesForTable(String table,
boolean uniqueOnly)
throws SQLException
SQLException
public void addIndex(String table,
String indexName,
boolean unique,
String... columns)
throws SQLException
SQLExceptionpublic String trimToLastDot(String name)
public void addPrimaryIndex(String table,
String... columns)
throws SQLException
SQLException
public void dropIndex(String table,
String index)
throws SQLException
SQLException
public boolean copyPrimaryKey(String sourceTable,
Connection target,
String targetTable)
throws SQLException
SQLException
public int copyIndices(String sourceTable,
Connection target,
String targetTable)
throws SQLException
SQLException
public HashMap<String,SimpleEntry<String,String>> getForeingKeys(String table)
throws SQLException
SQLException
public TableModelWrapper getForeignKeysModel(String table)
throws SQLException
SQLException
public HashMap<Object,Object> loadAsMap(String table,
String keyColumn,
String valueColumn,
Map<String,?> restrictions)
throws SQLException
SQLException
public Object getMaxValue(String table,
String columnField)
throws SQLException
SQLException
public Object getMinValue(String table,
String columnField)
throws SQLException
SQLException
public Object getSumValue(String table,
String columnField)
throws SQLException
SQLException
public Object getAverageValue(String table,
String columnField)
throws SQLException
SQLException
public int getCount(String table)
throws SQLException
SQLException
public int getCount(String table,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public Object getFunctionValue(String table,
String columnField,
SQLFunction func)
throws SQLException
SQLException
public Object getFunctionValue(String table,
String columnField,
String function)
throws SQLException
SQLException
public Object getFunctionValue(String table,
String columnField,
SQLFunction function,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public Object getFunctionValue(String table,
String columnField,
String function,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public Object getAggregatedFunctionValue(String table,
String column,
SQLFunction function,
String method,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public Object getAggregatedFunctionValue(String table,
String column,
String function,
String method,
Map<String,?> fieldRestrictions)
throws SQLException
table - the table to be queried (this may also be a select statement)column - the relevant column to be looked atfunction - the aggregation function to be usedmethod - allows to specify a method to be performed on the column (like
'len'); this may be nullfieldRestrictions - a restriction map that allows to filter the data
SQLException
public int getMaxTextLength(String table,
String textColumn,
Map<String,?> restrictions)
throws SQLException
SQLException
public HashSet<Object> getDistinctValues(String table,
String columnField)
throws SQLException
SQLException
public HashSet<Object> getDistinctValues(String table,
String columnField,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public int countDistinctValues(String table,
String columnField,
Map<String,?> restrictions)
throws SQLException
SQLException
public int replace(String table,
String column,
Object oldValue,
Object newValue)
throws SQLException
SQLException
public int update(String table,
String idColumn,
Object idValue,
String valueColumn,
Object newValue)
throws SQLException
SQLException
public int update(String table,
String column,
Object newValue,
Map<String,?> restrictions)
throws SQLException
SQLException
public HashMap<Object,Integer> getDistinctValuesWithCount(String table,
Map<String,?> fieldRestrictions,
String... columnField)
throws SQLException
SQLException
public HashMap<Object,Integer> getDistinctValuesWithCount(String table,
Map<String,?> fieldRestrictions,
Filter<Integer> numberFilter,
String... columnField)
throws SQLException
SQLException
public ResultSet queryDuplicates(String table,
String... duplicateColumns)
throws SQLException
SQLExceptionSubSelectCondition.createDuplicateConstraint(String, String...)
public Map<Object,Integer> findDuplicates(String table,
Map<String,?> restrictions,
String... column)
throws SQLException
SQLException
public AbstractIterator<Object> searchDuplicates(String table,
String column,
Map<String,?> restrictions)
throws SQLException
SQLException
public int insertRow(String tableName,
Object... values)
throws SQLException
SQLExceptioninsertRow(String, Map)
public int insertRow(String tableName,
Map<String,?> fieldValues)
throws SQLException
SQLException
public int insertRow(String tableName,
Map<String,?> fieldValues,
boolean ignoreInvalidColumns)
throws SQLException
ignoreInvalidColumns - if true, invalid column names are ignored as well as setting
invalid values on valid columns
SQLException
public int insertRowWithGeneratedKeys(String tableName,
Map<String,?> fieldValues)
throws SQLException
SQLException
public ResultSetTableModel getTableModel(String tableName,
String idColumnName,
Map<String,?> fieldRestrictions)
throws SQLException
tableName - the name of the table to be usedidColumnName - the name of the column representing the primary key; this may
be nullfieldRestrictions - mapping columnNames to values to which the result is to be
limited; may be null
SQLException
public TableModelWrapper loadTable(String table)
throws SQLException
SQLExceptionloadTable(ResultSet, boolean)
public TableModelWrapper loadTable(ResultSet rs,
boolean closeAfterUse)
throws SQLException
ResultSet.TYPE_FORWARD_ONLY
SQLException
public void importTableModel(String table,
TableModel model)
throws SQLException
SQLException
public void updateTable(String table,
String idColumn,
TableModel model)
throws IllegalArgumentException,
SQLException
IllegalArgumentException
SQLException
public int updateRows(String tableName,
String idField,
Object idValue,
Map<String,?> fieldValues)
throws SQLException,
IllegalArgumentException
SQLException - if any fieldValues cannot be stored.
IllegalArgumentException - if no row has been found to be updated
public int updateRows(String tableName,
String idField,
Object idValue,
Map<String,?> fieldValues,
boolean ignoreInvalidColumns)
throws SQLException,
IllegalArgumentException
IllegalArgumentException - if no row has been found to be updated.
SQLException
public boolean contains(RowItem row)
throws SQLException
SQLException
public boolean contains(String tableName,
String columnName,
Object value)
throws SQLException
SQLException
public void update(RowItem row)
throws SQLException,
IllegalArgumentException
SQLException
IllegalArgumentException
public void insert(RowItem row)
throws SQLException
SQLException
public void delete(RowItem row)
throws SQLException
SQLException
public int insertTableModel(String tableName,
TableModel model,
boolean batchMode)
throws SQLException
SQLException
public ArrayList<String> getColumnNames(String table)
throws SQLException
SQLException
public String[] getTableNames()
throws SQLException
SQLException
public String[] getViews()
throws SQLException
SQLException
public int executeUpdate(String sql,
Object... params)
throws SQLException
SQLException
public int deleteRow(String tableName,
String columnField,
Object columnValue)
throws SQLException
SQLException
public int deleteRows(String tableName,
Map<String,?> fieldRestrictions)
throws SQLException
SQLExceptionRange,
SQLConstraint
public HashMap<String,Object> getRow(String tableName,
String idField,
Object idValue)
throws SQLException
SQLException
public RowItem getRowItem(String tableName,
String idField,
Object idValue)
throws SQLException
SQLException
public ArrayList<HashMap<String,Object>> getTable(String tableName)
throws SQLException
SQLException
public void copyTable(String sourceTable,
Connection target,
String targetTable,
boolean createTable)
throws SQLException
target corresponding to
the given table in this Connection and transfers all data
SQLException
public void copyTable(String sourceTable,
Connection target,
String targetTable,
boolean createTable,
Monitor mon)
throws SQLException
target corresponding to
the given table in this Connection and transfers all data
SQLException
public int transferTable(String sourceTable,
Connection target,
String targetTable,
Monitor mon,
Map<String,?> restrictions)
throws SQLException
SQLException
public void copyTo(Connection target,
boolean createTables)
throws SQLException
SQLException
public String createTableString(ResultSetMetaData data,
String tableName)
throws SQLException
SQLException
public AbstractIterator<Map<String,Object>> iterate(ResultSet rs)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(String tableName,
String idField)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(String tableName,
String idField,
Filter<? super RowItem> filter)
throws SQLException
SQLException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public ArrayList<RowItem> getRowItems(ResultSet rs,
String idField,
Filter<? super RowItem> filter)
throws SQLException
SQLException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public ArrayList<RowItem> getRowItems(String tableName,
ResultSet rs,
String idField,
Filter<? super RowItem> filter)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(String tableName,
String idField,
Map<String,?> fieldRestrictions)
throws SQLException
SQLExceptionRange
@Warning(value="ResultSet is NOT automatically closed within this method!")
public ArrayList<HashMap<String,Object>> extractRows(ResultSet rs,
String... columns)
throws SQLException
SQLException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public HashMap<String,Object> extractRow(ResultSet rs,
String... columns)
throws SQLException
SQLException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public RowItem extractRowItem(ResultSet rs,
String idColumnName,
String... columns)
throws SQLException,
IllegalArgumentException
SQLException
IllegalArgumentException
public Object getValue(String tableName,
String idColumn,
Object idValue,
String valueColumn)
throws SQLException,
IllegalArgumentException
IllegalArgumentException - if the idValue was not found in the table
SQLException
public ResultSet filterTable(String tableName,
String columnName,
Object value)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue)
throws SQLException
SQLException
public ResultSet filterTableScrollable(String tableName,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public ResultSet filterTableUpdateable(String tableName,
Map<String,?> fieldRestrictions)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
Map<String,?> fieldRestrictions,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
throws SQLException,
ClassCastException
filterTable(tableName, fieldRestrictions, true, resultSetType, resultSetConcurrency, orderByColumns)
SQLException
ClassCastExceptionfilterTable(String, Map, boolean, int, int, String...)
public ResultSet filterTable(String tableName,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
throws SQLException,
ClassCastException
filterTable(String, String[], Map, boolean, int, int, String...)
with null for columns, so that '*' is used
SQLException
ClassCastException
public <T extends Exception> int updateRows(Processor<ResultSet,T> updater,
String table,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
Monitor mon)
throws SQLException,
T extends Exception,
CancellationWarning
SQLException
T extends Exception
CancellationWarning
public void processColumn(String table,
String column,
Processor<Object,?> processor,
Map<String,?> restrictions)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
String[] columns,
Map<String,?> fieldRestrictions,
boolean combineWithAndIfTrue,
int resultSetType,
int resultSetConcurrency,
String... orderByColumns)
throws SQLException,
ClassCastException
tableName - denotes the name of the table; if the String starts with
'select ', then the tableName is taken as a query string and
the 'columns'-parameter is ignored, as it is expected to be
already part of the select statementcolumns - if non-null and with a length of at least 1, the select
statement is not using '*' but the given columns insteadresultSetType - corresponds to the equivalent parameter in preparing a
statement for a connectionresultSetConcurrency - corresponds to the equivalent parameter in preparing a
statement for a connection
ClassCastException - if a Range object doesn't receive the expected type
SQLExceptionRange,
SQLConstraint,
Connection.prepareStatement(String, int, int),
getResultSet(int, int, String, Object...)
public ResultSet getResultSet(String sql,
Object... params)
throws SQLException
ResultSet.TYPE_FORWARD_ONLY and
ResultSet.CONCUR_READ_ONLY
SQLExceptiongetResultSet(int, int, String, Object...)
public ResultSet getResultSet(int resultSetType,
int resultSetConcurrency,
String sql,
Object... params)
throws SQLException
sql - specifies the sql statement to be executed (may contain
question marks that are resolved via parameters)resultSetType - corresponds to the equivalent parameter in preparing a
statement for a connectionresultSetConcurrency - corresponds to the equivalent parameter in preparing a
statement for a connection
SQLExceptionConnection.prepareStatement(String, int, int),
filterTable(String, String[], Map, boolean, int, int, String...)
public void addOrderBy(Appendable q,
String... orderByColumns)
public void addWhereClause(Appendable sql,
List<Object> parameters,
Map<String,?> restrictions)
addWhereClause(sql, parameters, restrictions, true)
addWhereClause(Appendable, List, Map, boolean)
public void addWhereClause(Appendable sql,
List<Object> parameters,
Map<String,?> restrictions,
boolean combineWithAndIfTrue)
SQLConstraint and also Object arrays (which will be translated
into an in(..) statement) even in combination with NotCondition
instances. Range and LikeCondition objects are supported
as restriction values. The values itself are only represented as question
marks within the String, i.e. they still need to be replaced by the
methods of PreparedStatement. This method will add all required
parameters to be bound to the given list of parameters.
sql - contains the current query string as it stands; this method
will add to itparameters - the current parameters that are to be set for binding the
query string to those; this method will add to itrestrictions - the map of restrictions, where a column name is mapped to its
restrictioncombineWithAndIfTrue - if true, multiple restrictions are combined with 'and',
otherwise with 'or'Range,
SQLConstraint
public void addWhereClause(Appendable sql,
List<Object> parameters,
String[] textColumns,
String... patternList)
sql - contains the current query string as it stands; this method
will add to itparameters - the current parameters that are to be set for binding the
query string to those; this method will add to ittextColumns - the text columns that are to be searched for the given patternpatternList - the pattern of which each has to be found in at least one of
the given columns
protected ResultSet getFirstRowFor(Statement stmt,
String tableNameOrQueryString)
throws SQLException
SQLException
public Hashtable<String,String> mapColumnNamesToDisplayNames(String tableNameOrQueryString)
throws SQLException
SQLException
public Hashtable<String,Integer> mapColumnNamesToSQLTypes(String tableNameOrQueryString)
throws SQLException
tableNameOrQueryString -
SQLException
public Hashtable<String,Integer> mapColumnNamesToSQLTypes(ResultSetMetaData meta)
throws SQLException
SQLException
public Hashtable<String,Integer> mapColumnNamesToSize(String tableNameOrQueryString)
throws SQLException
SQLException
public Hashtable<String,Integer> mapColumnNamesToSize(ResultSet rs)
throws SQLException
SQLException
public Hashtable<String,Integer> mapColumnNamesToSize(ResultSetMetaData meta)
throws SQLException
SQLException
public Hashtable<String,String> mapColumnNamesToTypeString(String tableNameOrQueryString)
throws SQLException
SQLException
public Hashtable<String,String> mapColumnNamesToTypeString(ResultSetMetaData meta)
throws SQLException
SQLException
@Deprecated
public DefaultTableModel getMetaDataAsTableModel(String tableName)
throws SQLException
SQLException
public ResultSet filterTableForText(String table,
String... patternList)
throws SQLException
SQLException
public ResultSet filterTableForText(String table,
String[] patternList,
String... restrictToColumn)
throws SQLException
SQLException
public ResultSet filterTableForText(int resultSetType,
int resultSetConcurrency,
String table,
String[] patternList,
String... restrictToColumn)
throws SQLException
SQLException
public void addWhereClauseOnSearchPattern(String[] patternList,
Appendable sb,
List<Object> params,
String table)
throws SQLException
patternList - the patterns that are to be searched forsb - contains the query string this method will add toparams - contains the parameters for the PreparedStatement which are
filled in parallel to the query stringtable - the name of the table to be searched
SQLException
public void addWhereClauseOnSearchPattern(String[] patternList,
Appendable sb,
List<Object> params,
Map<String,Integer> map,
String... columnNames)
patternList - the patterns that are to be searched forsb - contains the query string this method will add toparams - contains the parameters for the PreparedStatement which are
filled in parallel to the query stringmap - the meta data of the relevant query in a map that maps the
column name to its corresponding SQL type (can be easily
obtained via mapColumnNamesToSQLTypes(String))columnNames - if one or more column names are given, the search is only
conducted in these columnsmapColumnNamesToSQLTypes(ResultSetMetaData),
mapColumnNamesToSQLTypes(String)public DateFormat getDateFormat()
javaToSql(Object, int, int),
sqlToJava(Object, Class),
setDateFormat(DateFormat)public void setDateFormat(DateFormat dateFormat)
getDateFormat()
public <T> T sqlToJava(Object obj,
Class<T> requiredJavaType)
javaToSql(Object, int, int)
public Object javaToSql(Object obj,
int sqlType,
int size)
SQLConstraint are left intact
as they are supported in generating where-clauses; if they are used as
values for insert/update, they will create an error.
addWhereClause(Appendable, List, Map, boolean),
sqlToJava(Object, Class)
public ArrayList<RowItem> findInTable(String tableName,
String idColumn,
String pattern,
Monitor mon)
throws SQLException
SQLException
public void searchDatabaseFor(String text,
PrintStream ps,
Monitor monitor)
throws SQLException
SQLException
public String[] getCommonColumns(String... tables)
throws SQLException
SQLException
public void exportAsCSV(File file,
Monitor mon,
String sql,
Object... params)
throws SQLException,
IOException
SQLException
IOException
public void exportAsCSV(Writer writer,
Monitor mon,
String sql,
Object... params)
throws SQLException,
IOException
SQLException
IOException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public void exportAsCSV(ResultSet rs,
Writer writer,
Monitor mon)
throws SQLException,
IOException
SQLException
IOException
@Warning(value="ResultSet is NOT automatically closed within this method!")
public void exportAsCSV(ResultSet rs,
Writer writer,
Monitor mon,
boolean useQuotes,
String fieldSeparator,
String recordSeparator,
boolean includeHeader)
throws SQLException,
IOException
mon - used to monitor the progress; note, however, that the min/max
number is not automatically set!
SQLException
IOExceptionpublic static boolean isDateType(int sqlType)
Typespublic static boolean isCharType(int sqlType)
Typespublic static boolean isNumberType(int sqlType)
Typespublic static Range<Timestamp> convertTimestampRangeToSQL(Range<Date> range)
public static Range<Date> convertDateRangeToSQL(Range<Date> range)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||