public class DbTable
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private org.apache.log4j.Logger |
_logger
The _logger.
|
private java.util.List<java.lang.String> |
header
List containing the column headers.
|
private java.util.regex.Pattern |
removeSpecialCharacters
Regex to remove special characters that we don't want in the DB.
|
private java.util.List<java.util.List<java.lang.String>> |
table
List of List containing the full table.
|
Constructor and Description |
---|
DbTable()
Instantiates a new db table.
|
DbTable(java.util.List<java.util.List<java.lang.String>> data)
Create a table based on a List
|
DbTable(java.sql.ResultSet rs)
Create a table based on a ResultSet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addRow(java.util.List<java.lang.String> row)
Add a row of string values to the table.
|
java.util.HashMap<java.lang.String,java.lang.Object> |
findRow(java.lang.String columnName,
java.lang.String value)
Return a row based on a key/value pair.
|
java.util.List<java.lang.Integer> |
getColumnInt(java.lang.String headerName)
Get the values of a column as a List
|
java.util.List<java.lang.String> |
getColumnNames()
Get all the column names.
|
java.util.List<java.lang.String> |
getColumnString(java.lang.String headerName)
Get the values of a column as a List
|
java.lang.String |
getFirstValue(java.lang.String headerName)
Gets the first value in a column.
|
java.util.List<java.lang.String> |
getHeaders()
Return the names of all the columns.
|
java.util.HashMap<java.lang.String,java.lang.Object> |
getRowAsKeyVal(int row)
Return a row based on the index of that row
|
int |
getSize()
Return the number of rows in this table.
|
java.util.List<java.util.List<java.lang.String>> |
getTable()
Get all the rows.
|
static void |
main(java.lang.String[] args)
The main method.
|
static DbTable |
makeErrorTable(java.lang.String headerMsg,
java.lang.String rowMsg)
Make a table that contains an error message.
|
protected void |
parseResultSet(java.sql.ResultSet rs)
Parse the ResultSet into the table structure.
|
boolean |
setHeader(java.util.List<java.lang.String> columnNames)
Reset the table and set the headers.
|
java.util.List<java.util.HashMap<java.lang.String,java.lang.String>> |
toHashMapList()
Return the table as a List of HashMaps
|
java.lang.String |
toJsonString()
Return the entire table as a String
|
java.lang.String |
toString()
Return the entire table as a lightly-formatted String.
|
boolean |
writeToVizDb(DbHelper dbh,
java.lang.String tableName)
Write to viz db.
|
private java.util.List<java.lang.String> header
private java.util.List<java.util.List<java.lang.String>> table
private java.util.regex.Pattern removeSpecialCharacters
private org.apache.log4j.Logger _logger
public DbTable()
public DbTable(java.sql.ResultSet rs)
rs
- the rspublic DbTable(java.util.List<java.util.List<java.lang.String>> data)
data
- the datapublic int getSize()
public java.util.List<java.lang.String> getHeaders()
public java.util.List<java.util.List<java.lang.String>> getTable()
public java.util.List<java.lang.String> getColumnNames()
protected void parseResultSet(java.sql.ResultSet rs) throws java.sql.SQLException
rs
- the rsjava.sql.SQLException
- the SQL exceptionpublic java.util.List<java.lang.String> getColumnString(java.lang.String headerName)
headerName
- the header namepublic java.util.List<java.lang.Integer> getColumnInt(java.lang.String headerName)
headerName
- the header namepublic java.lang.String getFirstValue(java.lang.String headerName)
headerName
- the header namepublic java.util.HashMap<java.lang.String,java.lang.Object> findRow(java.lang.String columnName, java.lang.String value)
columnName
- the column namevalue
- the value to matchpublic java.util.HashMap<java.lang.String,java.lang.Object> getRowAsKeyVal(int row)
row
- the rowpublic boolean setHeader(java.util.List<java.lang.String> columnNames)
columnNames
- the column namespublic boolean addRow(java.util.List<java.lang.String> row)
row
- a Listpublic boolean writeToVizDb(DbHelper dbh, java.lang.String tableName)
dbh
- the dbhtableName
- the table namepublic java.lang.String toJsonString()
public java.lang.String toString()
toString
in class java.lang.Object
public static DbTable makeErrorTable(java.lang.String headerMsg, java.lang.String rowMsg)
headerMsg
- the header msgrowMsg
- the row msgpublic java.util.List<java.util.HashMap<java.lang.String,java.lang.String>> toHashMapList()
public static void main(java.lang.String[] args)
args
- the arguments