|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.util.SortableTable
SortableTable is a data structure that allows for easy and persistent storage of java.sql.ResultSets. SortableTables, unlike ResultSets, are not tied to any database connections, and so can be maintained without tying up database connections. SortableTables also have the added functionality of sorting by column. Both columns and rows may be added after the object is constructed. However, adding columns is very expensive, and rows which are added can only be added to the end of the structure.
Field Summary | |
static int |
ASCENDING
used to denote an ascending sort |
static int |
DATE
used to denote a Date comparison for sorting |
static int |
DESCENDING
used to denote a descending sort |
static int |
NUMBER
used to denote a number comparison for sorting |
static int |
STRING
used to denote a String comparison for sorting |
Constructor Summary | |
SortableTable()
Creates a SortableTable. |
|
SortableTable(int rowCapacity,
int columnCapacity)
Creates a SortableTable whose initial size is given by the specified parameters. |
|
SortableTable(int rowCapacity,
int columnCapacity,
int rowCapacityIncrement,
int columnCapacityIncrement)
creates a sortable table with the specified number of rows and columns. |
|
SortableTable(SortableTable source,
int startRow,
int endRow)
Creates a new table out of a subset of rows of another table All the columns of the source table are copied to the destination table. |
Method Summary | |
void |
changeNullsToString(int column,
java.lang.String alt)
change nulls in a column to an empty string ("") |
int |
doDelete(java.sql.Connection conn,
java.lang.String tableName)
Deletes all the Rows in the SortableTable. |
int |
doDelete(java.sql.Connection conn,
java.lang.String tableName,
java.lang.String[] constraintCols)
deletes all the rows in the sortableTable from the named table. |
int |
doInsert(java.sql.Connection conn,
java.lang.String tableName)
Inserts each row of the SortableTable into a table in the database. |
int |
doUpdate(java.sql.Connection conn,
java.lang.String tableName,
java.lang.String[] constraintCols)
Updates a table in the database based on the information in the SortableTable. |
java.util.Enumeration |
elements()
Returns an enumeration of all the objects in the table. |
void |
formatDateColumn(int column,
java.lang.String format)
change an entire column of timestamps to a column of strings containing formatted dates. |
java.lang.Object |
get(int rowIndex,
int columnIndex)
returns the object stored at the given indexes. |
java.lang.Object |
get(int rowIndex,
java.lang.String columnName)
returns the object stored at the given indexes. |
int |
getColumnIndex(java.lang.String name)
returns the column index denoted by the specified column name. |
java.lang.String |
getColumnName(int columnIndex)
returns the name of the columns at the specified column index. |
int |
getNumColumns()
returns the number of columns in the table. |
int |
getNumRows()
returns the number of rows in the table. |
int |
getSQLType(int columnIndex)
returns the column's SQL type. |
void |
insert(java.lang.Object obj,
int rowIndex,
int columnIndex)
inserts an object at the given indexes. |
void |
insert(java.lang.Object obj,
int rowIndex,
java.lang.String columnName)
inserts an object at the given row and column name. |
void |
load(java.sql.ResultSet rs,
boolean setNames)
loads data into the table from a ResultSet, starting at the first row and first column in the table |
void |
load(java.sql.ResultSet rs,
int startRow,
int startColumn,
boolean setNames)
loads data into the table from a ResultSet, beginning at the row whose index is specified, into the columns beginning with and following the columns whose index is specified. |
static SortableTable |
loadFromQuery(java.sql.Connection conn,
java.lang.String query)
loads a query specified by the string into the SortableTable that's returned. |
static SortableTable |
loadQuery(java.sql.Connection conn,
java.lang.String query)
loads a query specified by the string into the SortableTable that's returned. |
static java.lang.String |
printSQLType(int SQLType)
takes an int from java.sql.Types and returns it's name |
java.lang.Object |
remove(int rowIndex,
int columnIndex)
removes an object stored at the specified indexes from the table |
java.util.Enumeration |
rows()
returns an Enumeration of the rows in the table. |
void |
setColumnCapacity(int columnCapacity)
sets the number of columns to the specified size. |
void |
setColumnName(int columnIndex,
java.lang.String name)
sets the name of the column at the specified column index. |
void |
setRowCapacity(int rowCapacity)
sets the number of rows to the specified size. |
void |
setSQLType(int columnIndex,
int SQLType)
Sets the column SQL Type. |
void |
sort(int columnIndex,
int type,
int order)
sorts the table by the specified column index. |
void |
sort(java.lang.String columnName,
int type,
int order)
sorts the table by the specified column name. |
java.lang.String |
toHTML()
returns an HTML representation of the table, for easy data checking of handlers. |
java.lang.String |
toString()
Returns a string representation of the table. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int ASCENDING
public static final int DESCENDING
public static final int NUMBER
public static final int STRING
public static final int DATE
Constructor Detail |
public SortableTable()
Defaults: initial row capacity = 10; initial column capacity = 15 row capacity increment = 10; column capacity increment = 15
public SortableTable(int rowCapacity, int columnCapacity)
Defaults: row resize increment = 10; column resize increment = 15
public SortableTable(int rowCapacity, int columnCapacity, int rowCapacityIncrement, int columnCapacityIncrement)
public SortableTable(SortableTable source, int startRow, int endRow)
source
- the table to load the data fromstartRow
- the row of the source table to begin loading fromendRow
- the final row to load into the new tableMethod Detail |
public int getNumRows()
public int getNumColumns()
public void setRowCapacity(int rowCapacity)
public void setColumnCapacity(int columnCapacity)
public void load(java.sql.ResultSet rs, int startRow, int startColumn, boolean setNames) throws java.sql.SQLException
rs
- the ResultSet to load the information fromstartRow
- the index of the row to begin loading intostartColumn
- the index of the column to begin loading intosetNames
- whether to set the column names using the
ResultSetMetaData. Will also set the SQLType.public void load(java.sql.ResultSet rs, boolean setNames) throws java.sql.SQLException
rs
- the ResultSet to load the information fromsetNames
- whether to set the column names using the
ResultSetMetaDatapublic void insert(java.lang.Object obj, int rowIndex, int columnIndex)
public void insert(java.lang.Object obj, int rowIndex, java.lang.String columnName) throws java.lang.IllegalArgumentException
public java.lang.Object remove(int rowIndex, int columnIndex)
public java.lang.Object get(int rowIndex, int columnIndex)
public java.lang.Object get(int rowIndex, java.lang.String columnName)
public void setColumnName(int columnIndex, java.lang.String name)
public java.lang.String getColumnName(int columnIndex)
public int getColumnIndex(java.lang.String name)
public void setSQLType(int columnIndex, int SQLType)
columnIndex
- the column whose SQL Type is to be setSQLType
- one of the types specified in java.sql.Typesjava.sql.Types
public int getSQLType(int columnIndex)
columnIndex
- the column whose type to return.java.sql.Types
public void sort(java.lang.String columnName, int type, int order)
columnName
- the column name to sort bytype
- the kind of information in the column to sort (Given by the
constants NUMBER, DATE, or STRING)order
- the order (given by the constants ASCENDING or DESCENDING)
to sort bypublic void sort(int columnIndex, int type, int order)
columnIndex
- the column index to sort bytype
- the kind of information in the column to sort (Given by the
constants NUMBER, DATE, or STRING)order
- the order (given by the constants ASCENDING or DESCENDING)
to sort bypublic java.util.Enumeration rows()
public java.util.Enumeration elements()
public java.lang.String toString()
public java.lang.String toHTML()
public void formatDateColumn(int column, java.lang.String format)
table
- the table to updatecolumn
- the column to updateformat
- the format string to useSimpleDateFormat
public void changeNullsToString(int column, java.lang.String alt)
table
- the table to updatecolumn
- the column to updatealt
- the string to substitutepublic static SortableTable loadQuery(java.sql.Connection conn, java.lang.String query)
public static SortableTable loadFromQuery(java.sql.Connection conn, java.lang.String query) throws java.sql.SQLException
public int doUpdate(java.sql.Connection conn, java.lang.String tableName, java.lang.String[] constraintCols)
UPDATE <tableName> SET <column n name> = <column n value> WHERE <constraintcol 0< = <column n value>and runs it for each row in the sortableTable.
tableName
- the name of the table to updateconstraintCols
- an array containing the names of the columns
whose values should be used to constrain each updatepublic int doInsert(java.sql.Connection conn, java.lang.String tableName)
INSERT INTO <tableName> (<column 1 name>, <column 2 name>, <column n name>) VALUES (<column 1 value>, <column 2 value>, <column n value>)and runs it for each row in the sortableTable.
public int doDelete(java.sql.Connection conn, java.lang.String tableName)
tableName
- the name of the table to updatepublic int doDelete(java.sql.Connection conn, java.lang.String tableName, java.lang.String[] constraintCols)
DELETE FROM <tableName> WHERE <constraintCols 0> = <column n value> AND <constraintCols 1> = <column n value>where the constraintCol names specify the column values to use as constraints. The statement is run for every row in the table.
Note also that if a row contains any null elements, then the row will not be deleted, because nulls cannot be recognized as valid constraints using the '=' operator in SQL.
tableName
- the name of the table to updateconstraintCols
- an array containing the names of the columns
whose values should be used to constrain each updatepublic static java.lang.String printSQLType(int SQLType)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |