|
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 final class ConnectionHelper
The class JDBC provides several useful methods for handling JDBC connections.
JDBCTableModel| Constructor Summary | |
|---|---|
ConnectionHelper(Connection con)
|
|
| Method Summary | |
|---|---|
void |
copyTable(String origTable,
Connection target,
String copyTable,
boolean createTable)
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 |
static 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 idField,
Object idValue)
deletes all rows in the given table where the given field equals the given value |
int |
deleteRows(String tableName,
Map<String,Object> fieldRestrictions)
|
int |
executeUpdate(String sql)
shortcut to perform an update via SQL statement |
static RowItem |
extractRow(ResultSet rs,
String idField)
the current row should not have been accessed, yet |
ArrayList<HashMap<String,Object>> |
extractRows(ResultSet rs)
returns a map per row, where column names are mapped to their respective value. |
ResultSet |
filterTable(String tableName,
Map<String,Object> 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,Object> fieldRestrictions,
int resultSetType,
int resultSetConcurrency)
the integer parameters correspond to the prepare statement for the connection After being done w/ the ResultSet, it should be closed along w/ the corresponding statement. |
ResultSet |
filterTableUpdateable(String tableName,
Map<String,Object> fieldRestrictions)
returns an updateable and scrollable ResultSet. |
Object |
getAverageValue(String table,
String columnField)
|
Connection |
getConnection()
|
int |
getCount(String table)
|
Object |
getFunctionValue(String table,
String columnField,
String function)
returns the max value of the given field in the given table; null is returned if no entries were found in the database. |
Object |
getMaxValue(String table,
String columnField)
|
Object |
getMinValue(String table,
String columnField)
|
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 |
ArrayList<RowItem> |
getRowItems(ResultSet rs,
String idField,
Filter<RowItem> filter)
filter may be null |
ArrayList<RowItem> |
getRowItems(String tableName,
String idField,
Filter<RowItem> filter)
filter may be null |
ArrayList<RowItem> |
getRowItems(String tableName,
String idField,
Map<String,Object> 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,Object> fieldRestrictions)
returns a table model based on the table filtered by the given restrictions |
String[] |
getTableNames()
|
String[] |
getViews()
|
void |
insert(RowItem row)
|
int |
insertRow(String tableName,
Map<String,Object> fieldValues)
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 |
insertTableModel(String tableName,
TableModel model)
the table model is inserted based on the column order rather than column names. |
void |
setConnection(Connection con)
|
void |
update(RowItem row)
|
void |
updateRow(String tableName,
String idField,
Object idValue,
Map<String,Object> fieldValues)
updates the row in the given table by applying all of the given field values. |
void |
updateRow(String tableName,
String idField,
Object idValue,
Map<String,Object> fieldValues,
boolean ignoreInvalidColumns)
updates the row in the given table by applying the given field values. |
| 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 Connection getConnection()
public void setConnection(Connection con)
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 Object getFunctionValue(String table,
String columnField,
String function)
throws SQLException
SQLException
public int insertRow(String tableName,
Object... values)
throws SQLException
SQLExceptioninsertRow(String, Map)
public int insertRow(String tableName,
Map<String,Object> fieldValues)
throws SQLException
SQLException
public ResultSetTableModel getTableModel(String tableName,
String idColumnName,
Map<String,Object> 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 static RowItem extractRow(ResultSet rs,
String idField)
throws SQLException
SQLException
public void updateRow(String tableName,
String idField,
Object idValue,
Map<String,Object> fieldValues)
throws SQLException
SQLException
public void updateRow(String tableName,
String idField,
Object idValue,
Map<String,Object> fieldValues,
boolean ignoreInvalidColumns)
throws SQLException
SQLException
public void update(RowItem row)
throws SQLException
SQLException
public void insert(RowItem row)
throws SQLException
SQLException
public void delete(RowItem row)
throws SQLException
SQLException
public int insertTableModel(String tableName,
TableModel model)
throws SQLException
SQLException
public String[] getTableNames()
throws SQLException
SQLException
public String[] getViews()
throws SQLException
SQLException
public int executeUpdate(String sql)
throws SQLException
SQLException
public int deleteRow(String tableName,
String idField,
Object idValue)
throws SQLException
SQLException
public int deleteRows(String tableName,
Map<String,Object> fieldRestrictions)
throws SQLException
SQLException
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 origTable,
Connection target,
String copyTable,
boolean createTable)
throws SQLException
target corresponding to the given
table in this Connection and transfers all data
SQLException
public void copyTo(Connection target,
boolean createTables)
throws SQLException
SQLException
public static String createTableString(ResultSetMetaData data,
String tableName)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(String tableName,
String idField,
Filter<RowItem> filter)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(ResultSet rs,
String idField,
Filter<RowItem> filter)
throws SQLException
SQLException
public ArrayList<RowItem> getRowItems(String tableName,
String idField,
Map<String,Object> fieldRestrictions)
throws SQLException
SQLExceptionRange
public ArrayList<HashMap<String,Object>> extractRows(ResultSet rs)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
Map<String,Object> fieldRestrictions)
throws SQLException
SQLException
public ResultSet filterTableUpdateable(String tableName,
Map<String,Object> fieldRestrictions)
throws SQLException
SQLException
public ResultSet filterTable(String tableName,
Map<String,Object> fieldRestrictions,
int resultSetType,
int resultSetConcurrency)
throws SQLException,
ClassCastException
ClassCastException - if a Range object doesn't receive the expected type
SQLExceptionRange,
Connection.prepareStatement(String, int, int)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||