|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Table
A table is a database-like table that provides support for queries.
This code may be used freely by yourself with the following restrictions:
|
Nested Class Summary | |
---|---|
static interface |
Table.Exporter
Used for exporting tables in various formats. |
static interface |
Table.Importer
Used for importing tables in various formats. |
Field Summary | |
---|---|
static boolean |
ALL
A convenience constant that makes calls to commit(boolean)
and rollback(boolean) more readable when used as an
argument to those methods. |
static boolean |
THIS_LEVEL
A convenience constant that makes calls to commit(boolean)
and rollback(boolean) more readable when used as an
argument to those methods. |
Method Summary | |
---|---|
void |
begin()
begin a transaction |
Object |
clone()
Return a shallow copy of the table (the contents are not copied. |
void |
commit(boolean all)
Commit a transaction. |
int |
delete(com.holub.database.Selector where)
Delete from the table all rows approved by the Selector. |
void |
export(Table.Exporter importer)
Build a representation of the Table using the specified Exporter. |
int |
insert(Collection values)
A convenience overload of insert(Object[]) |
int |
insert(Collection columnNames,
Collection values)
A convenience overload of insert(String[],Object[]) |
int |
insert(Object[] values)
In this version of insert, values must have as many elements as there are columns, and the values must be in the order specified when the Table was created. |
int |
insert(String[] columnNames,
Object[] values)
Insert new values into the table corresponding to the specified column names. |
boolean |
isDirty()
Return true if this table has changed since it was created. |
String |
name()
Return the table name that was passed to the constructor (or read from the disk in the case of a table that was loaded from the disk.) |
void |
rename(String newName)
Rename the table to the indicated name. |
void |
rollback(boolean all)
Roll back a transaction. |
Cursor |
rows()
Return an iterator across the rows of the current table. |
Table |
select(com.holub.database.Selector where)
A more efficient version of select(where, null, null); |
Table |
select(com.holub.database.Selector where,
Collection requestedColumns)
Convenience method, translates Collection to String array, then calls String-array version. |
Table |
select(com.holub.database.Selector where,
Collection requestedColumns,
Collection other)
A convenience method that translates Collections to arrays, then calls select(Selector,String[],Table[]) ; |
Table |
select(com.holub.database.Selector where,
String[] requestedColumns)
A more efficient version of select(where, requestedColumns, null); |
Table |
select(com.holub.database.Selector where,
String[] requestedColumns,
Table[] other)
Create an unmodifiable table that contains selected rows from the current table. |
int |
update(com.holub.database.Selector where)
Update cells in the table. |
Field Detail |
---|
static final boolean THIS_LEVEL
commit(boolean)
and rollback(boolean)
more readable when used as an
argument to those methods.
Use commit(Table.THIS_LEVEL)
rather than
commit(false)
, for example.
static final boolean ALL
commit(boolean)
and rollback(boolean)
more readable when used as an
argument to those methods.
Use commit(Table.ALL)
rather than
commit(true)
, for example.
Method Detail |
---|
Object clone() throws CloneNotSupportedException
CloneNotSupportedException
String name()
void rename(String newName)
select(...)
or one of its variants.
boolean isDirty()
int insert(String[] columnNames, Object[] values)
values[i]
is put into the column specified
in columnNames[i]
. Columns that are not
specified are initialized to null
.
IndexOutOfBoundsException
- One of the requested columns
doesn't exist in either table.int insert(Collection columnNames, Collection values)
insert(String[],Object[])
int insert(Object[] values)
int insert(Collection values)
insert(Object[])
int update(com.holub.database.Selector where)
Selector
object serves
as a visitor whose includeInSelect(...)
method
is called for each row in the table. The return value is ignored,
but the Selector can modify cells as it examines them. Its your
responsibility not to modify primary-key and other constant
fields.
int delete(com.holub.database.Selector where)
void begin()
void commit(boolean all) throws IllegalStateException
all
- if false, commit only the innermost transaction,
otherwise commit all transactions at all levels.
IllegalStateException
- if no begin()
was issued.THIS_LEVEL
,
ALL
void rollback(boolean all) throws IllegalStateException
all
- if false, commit only the innermost transaction,
otherwise commit all transactions at all levels.
IllegalStateException
- if no begin()
was issued.THIS_LEVEL
,
ALL
Table select(com.holub.database.Selector where, String[] requestedColumns, Table[] other)
Selector
argument
specifies a strategy object that determines which
rows will be included in the result.
Table
.
If the other
argument is present, this methods
"joins" all rows
from the current table and the other
table and
then selects rows from the "join."
If the two tables contain identically named columns, then
only the column from the current table is included in the
result.
Joins are performed by creating the Cartesian product of the current and "other" tables, using the Selector to determine which rows of the product to include in the returned Table. For example, If one table contains:
a b c dand the
other
table contains
e f g hthen the Cartesian product is the table
a b e f a b g h c d e f c d g hIn the case of a join, the selector is presented with rows from this product.
The Table
returned from select(com.holub.database.Selector, java.lang.String[], com.holub.database.Table[])
cannot be modified by you. The methods Table
methods that normally modify the
table (insert, update, delete, store) throw an
UnsupportedOperationException
if call them.
where
- a selector that determines which rows to include
in the result.
Use Selector.ALL
to include all rows.requestedColumns
- columns to include in the result.
null for all columns.other
- Other tables to join to this one. At most
three other tables may be specified.
This argument must be null if you're not doing a join.
other
table
that were accepted by the Selector
.
IndexOutOfBoundsException
- One of the requested columns
doesn't exist in either table.Table select(com.holub.database.Selector where, String[] requestedColumns)
select(where, requestedColumns, null);
Table select(com.holub.database.Selector where)
select(where, null, null);
Table select(com.holub.database.Selector where, Collection requestedColumns, Collection other)
select(Selector,String[],Table[])
;
requestedColumns
- a collection of String objects
representing the desired columns.other
- a collection of additional Table objects to join to
the current one for the purposes of this SELECT
operation.Table select(com.holub.database.Selector where, Collection requestedColumns)
Cursor rows()
void export(Table.Exporter importer) throws IOException
Table.Importer
using the constructor with an
Table.Importer
argument. The table's
"dirty" status is cleared (set false) on an export.
IOException
isDirty()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |