Interface Table<R>
- All Superinterfaces:
AutoCloseable
,Closeable
@PrimaryKey("id")
public interface MyRow {
long id();
void id(long id);
String name();
void name(String str);
String message();
void message(String str);
}
Supported column types:
- Simple objects —
String
,BigInteger
, andBigDecimal
- Primitives —
int
,double
, etc - Boxed primitives —
Integer
,Double
, etc - Primitive arrays —
int[]
,double[]
, etc
IllegalArgumentException
to be thrown. The column definition must be annotated with @Nullable
to support nulls.
The actual row implementation class is generated at runtime, and the standard
equals
, hashCode
, toString
, and clone
methods are automatically
generated as well. If the row interface declares a clone
method which returns the
exact row type, then the row can be cloned without requiring an explicit cast. If the row
interface extends Comparable
, then rows are comparable by primary key. Any default
methods defined in the row interface are never overridden by the generated class, unless the
method is defined in the Object
class.
Scans over the rows of the table can be reduced by a query, described by this syntax:
Note that a query projection specifies the minimum set of requested columns, but additional ones might be provided if they were needed by the query implementation.Query = RowFilter | Projection [ RowFilter ] RowFilter = AndFilter { "||" AndFilter } AndFilter = EntityFilter { "&&" EntityFilter } EntityFilter = ColumnFilter | ParenFilter ParenFilter = [ "!" ] "(" [ RowFilter ] ")" ColumnFilter = ColumnName RelOp ( ArgRef | ColumnName ) | ColumnName "in" ArgRef | ArgRef RelOp ColumnName RelOp = "==" | "!=" | ">=" | "<" | "<=" | ">" Projection = "{" ProjColumns "}" ProjColumns = [ ProjColumn { "," ProjColumn } ] ProjColumn = ( ( ( ( "+" | "-" ) [ "!" ] ) | "~" ) ColumnName ) | "*" ColumnName = string ArgRef = "?" [ uint ]
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> Table
<T> aggregate
(Class<T> targetType, Aggregator.Factory<R, T> factory) Returns a view backed by this table, consisting of aggregate rows, which are grouped by theprimary key
of the target type.default boolean
anyRows
(Transaction txn) Returns true if any rows exist in this table.default boolean
anyRows
(Transaction txn, String query, Object... args) Returns true if a subset of rows from this table exists, as specified by the query expression.default boolean
anyRows
(R row, Transaction txn, String query, Object... args) Returns true if a subset of rows from this table exists, as specified by the query expression.void
Sets columns which have a dirty state to clean.Returns a new row instance which is an exact copy of the given row.void
close()
default Comparator
<R> comparator
(String spec) Returns a row comparator based on the given specification, which defines the ordering columns.static <T> Table
<T> Returns a view consisting of all rows from the given source tables concatenated together, possibly resulting in duplicate rows.Returns a view consisting of all rows from the given source tables concatenated together, possibly resulting in duplicate rows.void
Copies all columns and states from one row to another.default void
delete
(Transaction txn, R row) Unconditionally removes an existing row by primary key.<D> Table
<D> Returns a view backed by this table, specified by a fully-featured query expression.Returns a view backed by this table, specified by a fully-featured query expression.distinct()
Returns a view of this table which has duplicate rows filtered out.default R
exchange
(Transaction txn, R row) Unconditionally stores the given row, potentially replacing a corresponding row which already exists.boolean
exists
(Transaction txn, R row) Checks if a row exists by searching against the primary key.void
forEach
(R row, ColumnProcessor<? super R> action) For the given row, performs an action for each column which is set.default <T> Table
<T> Returns a view backed by this table, which processes groups of source rows into groups of target rows.boolean
Returns true if this table has a primary key defined, as specified by therow type
.default void
insert
(Transaction txn, R row) Stores the given row when a corresponding row doesn't exist.boolean
isClosed()
boolean
isEmpty()
Non-transactionally determines if the table has nothing in it.boolean
Returns true if the given row column is set.join()
Returns an unmodifiable table consisting of one row with no columns, representing the identity element when joining an empty set of tables.static <J> Table
<J> Joins tables together into an unmodifiable view.Joins tables together into a generated join type class.default void
load
(Transaction txn, R row) Fully loads the row by primary key.default <T> Table
<T> Returns a view backed by this table, whose rows have been mapped to target rows, applying any necessary column value conversions.default <T> Table
<T> Returns a view backed by this table, whose rows have been mapped to target rows.default void
merge
(Transaction txn, R row) Updates an existing row with the modified columns of the given row, and then loads the result back into the given row.newRow()
Returns a new row instance with unset columns.newScanner
(Transaction txn) Returns a new scanner for all rows of this table.newScanner
(Transaction txn, String query, Object... args) Returns a new scanner for a subset of rows from this table, as specified by the query expression.newScanner
(R row, Transaction txn) Returns a new scanner for all rows of this table.newScanner
(R row, Transaction txn, String query, Object... args) Returns a new scanner for a subset of rows from this table, as specified by the query expression.newStream
(Transaction txn) Returns a new stream for all rows of this table.newStream
(Transaction txn, String query, Object... args) Returns a new stream for a subset of rows from this table, as specified by the query expression.newTransaction
(DurabilityMode durabilityMode) Returns a new transaction which is compatible with this table.newUpdater
(Transaction txn) Returns a new updater for all rows of this table.newUpdater
(Transaction txn, String query, Object... args) Returns a new updater for a subset of rows from this table, as specified by the query expression.newUpdater
(R row, Transaction txn) Returns a new updater for all rows of this table.newUpdater
(R row, Transaction txn, String query, Object... args) Returns a new updater for a subset of rows from this table, as specified by the query expression.Returns a row predicate for the given query expression and arguments.Returns a query for a subset of rows from this table, as specified by the query expression.queryAll()
Returns a query for all rows of this table.default void
replace
(Transaction txn, R row) Stores the given row when a corresponding row already exists.rowType()
Returns the interface which defines the rows of this table.default void
store
(Transaction txn, R row) Unconditionally stores the given row, potentially replacing a corresponding row which already exists.default boolean
tryDelete
(Transaction txn, R row) Unconditionally removes an existing row by primary key.default boolean
tryInsert
(Transaction txn, R row) Stores the given row when a corresponding row doesn't exist.boolean
tryLoad
(Transaction txn, R row) Fully loads the row by primary key.default boolean
tryMerge
(Transaction txn, R row) Updates an existing row with the modified columns of the given row, and then loads the result back into the given row.default boolean
tryReplace
(Transaction txn, R row) Stores the given row when a corresponding row already exists.default boolean
tryUpdate
(Transaction txn, R row) Updates an existing row with the modified columns of the given row, but the resulting row isn't loaded back.void
Resets the state of the given row such that all columns are unset.default void
update
(Transaction txn, R row) Updates an existing row with the modified columns of the given row, but the resulting row isn't loaded back.
-
Method Details
-
hasPrimaryKey
boolean hasPrimaryKey()Returns true if this table has a primary key defined, as specified by therow type
. -
rowType
-
newRow
R newRow()Returns a new row instance with unset columns. -
cloneRow
-
unsetRow
Resets the state of the given row such that all columns are unset. -
cleanRow
Sets columns which have a dirty state to clean. All unset columns remain unset. -
copyRow
-
isSet
Returns true if the given row column is set.- Throws:
IllegalArgumentException
- if column is unknown
-
forEach
For the given row, performs an action for each column which is set. -
newScanner
Returns a new scanner for all rows of this table.- Parameters:
txn
- optional transaction for the scanner to use; pass null for auto-commit mode- Returns:
- a new scanner positioned at the first row in the table
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newScanner
Returns a new scanner for all rows of this table.- Parameters:
row
- row instance for the scanner to use; pass null to create a new instancetxn
- optional transaction for the scanner to use; pass null for auto-commit mode- Returns:
- a new scanner positioned at the first row in the table
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newScanner
Returns a new scanner for a subset of rows from this table, as specified by the query expression.- Parameters:
txn
- optional transaction for the scanner to use; pass null for auto-commit mode- Returns:
- a new scanner positioned at the first row in the table accepted by the query
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newScanner
default Scanner<R> newScanner(R row, Transaction txn, String query, Object... args) throws IOException Returns a new scanner for a subset of rows from this table, as specified by the query expression.- Parameters:
row
- row instance for the scanner to use; pass null to create a new instancetxn
- optional transaction for the scanner to use; pass null for auto-commit mode- Returns:
- a new scanner positioned at the first row in the table accepted by the query
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newUpdater
Returns a new updater for all rows of this table.When providing a transaction which acquires locks (or the transaction is null), upgradable locks are acquired for each row visited by the updater. If the transaction lock mode is non-repeatable, any lock acquisitions for rows which are stepped over are released when moving to the next row. Updates with a null transaction are auto-committed and become visible to other transactions as the updater moves along.
- Parameters:
txn
- optional transaction for the updater to use; pass null for auto-commit mode- Returns:
- a new updater positioned at the first row in the table
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newUpdater
Returns a new updater for all rows of this table.When providing a transaction which acquires locks (or the transaction is null), upgradable locks are acquired for each row visited by the updater. If the transaction lock mode is non-repeatable, any lock acquisitions for rows which are stepped over are released when moving to the next row. Updates with a null transaction are auto-committed and become visible to other transactions as the updater moves along.
- Parameters:
row
- row instance for the updater to use; pass null to create a new instancetxn
- optional transaction for the updater to use; pass null for auto-commit mode- Returns:
- a new updater positioned at the first row in the table
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newUpdater
Returns a new updater for a subset of rows from this table, as specified by the query expression.When providing a transaction which acquires locks (or the transaction is null), upgradable locks are acquired for each row visited by the updater. If the transaction lock mode is non-repeatable, any lock acquisitions for rows which are stepped over are released when moving to the next row. Updates with a null transaction are auto-committed and become visible to other transactions as the updater moves along.
- Parameters:
txn
- optional transaction for the updater to use; pass null for auto-commit mode- Returns:
- a new updater positioned at the first row in the table accepted by the query
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newUpdater
default Updater<R> newUpdater(R row, Transaction txn, String query, Object... args) throws IOException Returns a new updater for a subset of rows from this table, as specified by the query expression.When providing a transaction which acquires locks (or the transaction is null), upgradable locks are acquired for each row visited by the updater. If the transaction lock mode is non-repeatable, any lock acquisitions for rows which are stepped over are released when moving to the next row. Updates with a null transaction are auto-committed and become visible to other transactions as the updater moves along.
- Parameters:
row
- row instance for the updater to use; pass null to create a new instancetxn
- optional transaction for the updater to use; pass null for auto-commit mode- Returns:
- a new updater positioned at the first row in the table accepted by the query
- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newStream
Returns a new stream for all rows of this table. The stream must be explicitly closed when no longer used, or else it must be used with a try-with-resources statement. If an underlyingIOException
is generated, it's thrown as if it was unchecked.- Parameters:
txn
- optional transaction for the stream to use; pass null for auto-commit mode- Returns:
- a new stream positioned at the first row in the table
- Throws:
IllegalStateException
- if transaction belongs to another database instance
-
newStream
Returns a new stream for a subset of rows from this table, as specified by the query expression. The stream must be explicitly closed when no longer used, or else it must be used with a try-with-resources statement. If an underlyingIOException
is generated, it's thrown as if it was unchecked.- Parameters:
txn
- optional transaction for the stream to use; pass null for auto-commit mode- Returns:
- a new stream positioned at the first row in the table accepted by the query
- Throws:
IllegalStateException
- if transaction belongs to another database instance
-
query
Returns a query for a subset of rows from this table, as specified by the query expression.- Throws:
IOException
-
queryAll
Returns a query for all rows of this table.- Throws:
IOException
-
anyRows
Returns true if any rows exist in this table.- Parameters:
txn
- optional transaction to use; pass null for auto-commit mode- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
- See Also:
-
anyRows
Returns true if a subset of rows from this table exists, as specified by the query expression.- Parameters:
txn
- optional transaction to use; pass null for auto-commit mode- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
anyRows
Returns true if a subset of rows from this table exists, as specified by the query expression.- Parameters:
row
- row instance for the implementation to use; pass null to create a new instance if necessarytxn
- optional transaction to use; pass null for auto-commit mode- Throws:
IllegalStateException
- if transaction belongs to another database instanceIOException
-
newTransaction
Returns a new transaction which is compatible with this table. If the provided durability mode is null, a default mode is selected. -
isEmpty
Non-transactionally determines if the table has nothing in it. A return value of true guarantees that the table is empty, but false negatives are possible.- Throws:
IOException
- See Also:
-
load
Fully loads the row by primary key.- Throws:
IllegalStateException
- if primary key isn't fully specifiedNoSuchRowException
- if a corresponding row doesn't existIOException
-
tryLoad
Fully loads the row by primary key.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if primary key isn't fully specifiedIOException
-
exists
Checks if a row exists by searching against the primary key. This method should be called only if the row doesn't need to be loaded or stored — calling exists and then calling a load or store method is typically less efficient than skipping the exists check entirely.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if primary key isn't fully specifiedIOException
-
store
Unconditionally stores the given row, potentially replacing a corresponding row which already exists.- Throws:
IllegalStateException
- if any required columns aren't setUniqueConstraintException
- if a conflicting alternate key existsIOException
-
exchange
Unconditionally stores the given row, potentially replacing a corresponding row which already exists.- Returns:
- a copy of the replaced row, or null if none existed
- Throws:
IllegalStateException
- if any required columns aren't setUniqueConstraintException
- if a conflicting alternate key existsIOException
-
insert
Stores the given row when a corresponding row doesn't exist.- Throws:
IllegalStateException
- if any required columns aren't setUniqueConstraintException
- if a conflicting primary or alternate key existsIOException
-
tryInsert
Stores the given row when a corresponding row doesn't exist.- Returns:
- false if a corresponding row already exists and nothing was inserted
- Throws:
IllegalStateException
- if any required columns aren't setUniqueConstraintException
- if a conflicting alternate key existsIOException
-
replace
Stores the given row when a corresponding row already exists.- Throws:
IllegalStateException
- if any required columns aren't setNoSuchRowException
- if a corresponding row doesn't existUniqueConstraintException
- if a conflicting alternate key existsIOException
-
tryReplace
Stores the given row when a corresponding row already exists.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if any required columns aren't setUniqueConstraintException
- if a conflicting alternate key existsIOException
-
update
Updates an existing row with the modified columns of the given row, but the resulting row isn't loaded back.- Throws:
IllegalStateException
- if primary key isn't fully specifiedNoSuchRowException
- if a corresponding row doesn't existUniqueConstraintException
- if a conflicting alternate key existsIOException
-
tryUpdate
Updates an existing row with the modified columns of the given row, but the resulting row isn't loaded back.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if primary key isn't fully specifiedUniqueConstraintException
- if a conflicting alternate key existsIOException
-
merge
Updates an existing row with the modified columns of the given row, and then loads the result back into the given row.- Throws:
IllegalStateException
- if primary key isn't fully specifiedNoSuchRowException
- if a corresponding row doesn't existUniqueConstraintException
- if a conflicting alternate key existsIOException
-
tryMerge
Updates an existing row with the modified columns of the given row, and then loads the result back into the given row.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if primary key isn't fully specifiedUniqueConstraintException
- if a conflicting alternate key existsIOException
-
delete
Unconditionally removes an existing row by primary key.- Throws:
IllegalStateException
- if primary key isn't fully specifiedNoSuchRowException
- if a corresponding row doesn't existIOException
-
tryDelete
Unconditionally removes an existing row by primary key.- Returns:
- false if a corresponding row doesn't exist
- Throws:
IllegalStateException
- if primary key isn't fully specifiedIOException
-
map
Returns a view backed by this table, whose rows have been mapped to target rows. The returned table instance will throw aViewConstraintException
for operations against rows not supported by the mapper, and closing the table has no effect.- Throws:
NullPointerException
- if any parameter is nullIOException
-
map
Returns a view backed by this table, whose rows have been mapped to target rows, applying any necessary column value conversions. The returned table instance will throw aConversionException
for operations against rows which cannot be converted back source rows, and closing the table has no effect.Source column values are converted to target column values using a potentially lossy conversion, which can cause numbers to be clamped to a narrower range, etc. Columns which aren't mapped to the target are dropped, and columns which don't map from the source are set to the most appropriate default value, preferably null.
- Parameters:
targetType
- target row type; the primary key is possibly ignored- Throws:
NullPointerException
- if any parameter is nullIOException
-
aggregate
default <T> Table<T> aggregate(Class<T> targetType, Aggregator.Factory<R, T> factory) throws IOExceptionReturns a view backed by this table, consisting of aggregate rows, which are grouped by theprimary key
of the target type. The primary key columns must exactly correspond to columns of this source table. If no primary key is defined, then the resulting table has one row, which is the aggregate result of all the rows of this table. The view returned by this method is unmodifiable, and closing it has no effect.- Throws:
NullPointerException
- if any parameter is nullIllegalArgumentException
- if target primary key is malformedIOException
-
group
default <T> Table<T> group(String groupBy, String orderBy, Class<T> targetType, Grouper.Factory<R, T> factory) throws IOExceptionReturns a view backed by this table, which processes groups of source rows into groups of target rows. The view returned by this method is unmodifiable, closing it has no effect, and aViewConstraintException
is thrown from operations which act upon a primary key.- Parameters:
groupBy
- groupingspecification
; pass an empty string to group all source rows togetherorderBy
- ordering specification within each group; pass an empty string if undefined- Throws:
NullPointerException
- if any parameter is nullIllegalArgumentException
- if groupBy or orderBy specification is malformedIllegalStateException
- if any groupBy or orderBy columns don't existIOException
-
join
Joins tables together into an unmodifiable view. The returned view doesn't have any primary key, and so operations which act upon one aren't supported. In addition, closing the view doesn't have any effect.The
joinType
parameter is a class which resembles an ordinary row definition except that all columns must refer to other row types. Any annotations which define keys and indexes are ignored.The join specification consists of each join column, separated by a join operator, and possibly grouped with parenthesis:
JoinOp = Source { Type Source } Source = Column | Group Group = "(" JoinOp ")" Column = string Type = ":" | ">:" | ":<" | ">:<" | ">" | "<" | "><" a : b inner join a >: b left outer join a :< b right outer join a >:< b full outer join a > b left anti join a < b right anti join a >< b full anti join
In order for a requested join type to work correctly, a suitable join filter must be provided by a query. Scanning all rows of the table without a join filter results in a cross join.
- Parameters:
spec
- join specification- Throws:
NullPointerException
- if any parameters are nullIllegalArgumentException
- if join type is malformed, or if the specification is malformed, or if there are any table matching issuesIOException
- See Also:
-
join
Joins tables together into a generated join type class.- Parameters:
spec
- join specification- Throws:
NullPointerException
- if any parameters are nullIllegalArgumentException
- if the specification is malformed, or if there are any table matching issuesIOException
- See Also:
-
join
-
derive
Returns a view backed by this table, specified by a fully-featured query expression. The returned table instance will throw aViewConstraintException
for operations against rows which are restricted by the query, and closing the table has no effect.- Parameters:
derivedType
- the projected query columns must correspond to columns defined in the derived row type- Throws:
IOException
-
derive
Returns a view backed by this table, specified by a fully-featured query expression. The returned table instance will throw aViewConstraintException
for operations against rows which are restricted by the query, and closing the table has no effect.- Throws:
IOException
-
concat
Returns a view consisting of all rows from the given source tables concatenated together, possibly resulting in duplicate rows. All of the rows are mapped to the target type, applying any necessary column value conversions. The returned table instance will throw aConversionException
for operations against rows which cannot be converted back source rows, and closing the table has no effect.- Parameters:
targetType
- target row type; the primary key is possibly ignoredsources
- source tables to concatenate; if none are provided, then the returned view is empty- Throws:
NullPointerException
- if any parameter is nullIOException
- See Also:
-
concat
Returns a view consisting of all rows from the given source tables concatenated together, possibly resulting in duplicate rows. All of the rows are mapped to an automatically selected target type (possibly generated), applying any necessary column value conversions. The returned table instance will throw aConversionException
for operations against rows which cannot be converted back source rows, and closing the table has no effect.- Parameters:
sources
- source tables to concatenate; if none are provided, then the returned view is empty- Returns:
- a table whose row type primary key consists of all the source columns, but the table doesn't actually have a primary key
- Throws:
NullPointerException
- if any parameter is nullIOException
- See Also:
-
distinct
Returns a view of this table which has duplicate rows filtered out. If this table doesn't have any duplicates, then it's simply returned as-is. If an actual view is returned, then the instance is unmodifiable, and closing it has no effect.- Throws:
IOException
-
comparator
Returns a row comparator based on the given specification, which defines the ordering columns. Each column name is prefixed with '+' or '-', to indicate ascending or descending order. For example:"+lastName+firstName-birthdate"
. By default, nulls are treated as higher than non-nulls, but a '!' after the '+'/'-' character causes nulls to be treated as lower than non-nulls.- Throws:
IllegalArgumentException
- if the specification is malformedIllegalStateException
- if the specification refers to non-existent columns
-
predicate
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- See Also:
-
isClosed
boolean isClosed()
-