Class CustomTable
Table interface to learn about the motivation of a custom table
class.)
At a minimum, a concrete custom table class declares for each column a
variable (typically with the final modifier) referencing that column,
for example,
final Column<String> myStringColumn =The column variable can be declared as a class variable, hence, with aCL.typeString(); final Column<String> myStringArrayColumn = CL.ofArray(Scheme.OUTROW, 58,ST.beString()); final Column<Ref> myRefColumn = CL.ofRef()
static modifier under the same condition that a table variable can
be declared as a class variable in a custom database.
See the description of the CustomDatabase class for details.
Besides the column declarations, the table must provide the table
definition at the time of object creation by invoking the initialize method, see example below.
(The table definition is the characteristic sequence of columns of a table,
see the description of the Table interface.)
If you plan to use the Setup Tool for creating the
database layout and all backing files of the database then make sure that
the table class is declared with a public access level modifier and
that it is annotated with the @SetupTable
annotation.
Furthermore, the table class must have a no-arg public constructor
and all column declarations in the table class need to have a public
access level modifier and must be annotated with the
@SetupColumn annotation, for example,
@SetupTable({ "My String Column, My String Array Column, My Ref Column" })
class MyTable {
@SetupColumn("My String Column")
final Column<String> myStringColumn = CL.ofString();
@SetupColumn("My String Array Column")
final Column<String> myStringArrayColumn =
CL.ofArray(Scheme.OUTROW, 58, ST.beString());
@SetupColumn(value = "My Ref Column", refdTable = "My Referenced Table")
final Column<Ref> myRefColumn = CL.ofRef()
MyTable() {
initialize(myStringColumn, myStringArrayColumn, myRefColumn);
}
}
Note that the write operations (insert, update, etc.) are
not declared final.
Concrete table classes can overwrite these methods and restrict their use.
For example, clients of a concrete table class could be prevented from
inserting values that were not previously checked for their domain-specific
validity.
- Author:
- Beat Hörmann
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal voidvoidfinal Rowfinal acdp.internal.Table_getBackingTable(acdp.internal.Database_.Friend friend) Friend-only access to the internal backing table object.final CustomDatabaseReturns the database.final <T> TReturns the value stored at the specified row and column in this table.final Information.TableInfoinfo()See Table.info()protected voidinitialize(Column<?>... columns) Initializes this custom table.final Table.TableIteratoriterator()See Table.iterator()final Table.TableIteratorfinal Table.TableIteratorfinal Stringname()See Table.name()final longfinal longtoString()See Table.toString()voidtruncate()See Table.truncate()voidvoid<T> voidupdateAllChangeValues(Column<T> column, Table.ValueChanger<T> valueChanger) <T> voidupdateAllSupplyValues(Column<T> column, Table.ValueSupplier<T> valueSupplier) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CustomTable
protected CustomTable()The constructor. (Javadoc 19 generates a warning if there is no comment.)
-
-
Method Details
-
initialize
Initializes this custom table.Invoke this method in the constructor of the concrete custom table class. If you do not call this method, almost all methods of this class will throw a
NullPointerException.The order of the columns in the specified array of columns must be the same as the order in which the corresponding column layouts appear in the database layout.
- Parameters:
columns- The array of columns of the table, not allowed to benulland not allowed to be empty. The table definition is set equal to a copy of this array.- Throws:
IllegalArgumentException- Ifcolumnsisnullor empty or if it contains anullvalue.
-
getBackingTable
public final acdp.internal.Table_ getBackingTable(acdp.internal.Database_.Friend friend) throws NullPointerException Friend-only access to the internal backing table object. (Since the friend resides in a different package, this method has to be public.)- Parameters:
friend- The friend, not allowed to benull.- Returns:
- The backing table, never
null. - Throws:
NullPointerException- Iffriendisnull.
-
name
See Table.name()- Returns:
- The name of the table, never
nulland never an empty string.
-
info
See Table.info()- Returns:
- The information object of the table, never
null.
-
getDatabase
Returns the database.- Returns:
- The database.
-
numberOfRows
public final long numberOfRows()- Returns:
- The number of rows.
-
insert
public Ref insert(Object... values) throws UnsupportedOperationException, NullPointerException, IllegalArgumentException, MaximumException, CryptoException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Parameters:
values- The values to insert into the row.- Returns:
- The reference to the inserted row.
- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- Ifvaluesisnull.IllegalArgumentException- If the number of values is not equal to the number of columns of the table. This exception also happens if for at least one value the length of the byte representation of the value (or one of the elements if the value is an array value) exceeds the maximum length allowed by the simple column type. Furthermore, this exception happens if for at least one value the value is a reference and the reference points to a row that does not exist within the referenced table or if the reference points to a row gap or if the value is an array of references and this condition is satisfied for at least one of the references contained in the array.MaximumException- If a new memory block in the VL file space must be allocated and its file position exceeds the maximum allowed position or if the maximum value of the reference counter of a referenced row is exceeded or if the maximum number of rows for this table is exceeded.CryptoException- If encryption fails. This exception never happens if the WR database does not apply encryption.ShutdownException- If this insert operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this insert operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
update
public void update(Ref ref, ColVal<?>... colVals) throws UnsupportedOperationException, NullPointerException, IllegalArgumentException, IllegalReferenceException, MaximumException, CryptoException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Parameters:
ref- The reference to the row to update.colVals- The array of column values.- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- If one of the arguments is equal tonullor if the array of column values contains an element equal tonull.IllegalArgumentException- If the array of column values contains at least one column that is not a column of the table. This exception also happens if for at least one value the length of the byte representation of the value (or one of the elements if the value is an array value) exceeds the maximum length allowed by this type. Furthermore, this exception happens if for at least one value the value is a reference and the reference points to a row that does not exist within the referenced table or if the reference points to a row gap or if the value is an array of references and this condition is satisfied for at least one of the references contained in the array.IllegalReferenceException- If the specified reference points to a row that does not exist within the table or if the reference points to a row gap. Such a situation cannot occur ifrefis a valid reference.MaximumException- If a new memory block in the VL file space must be allocated and its file position exceeds the maximum allowed position or if the maximum value of the reference counter of a referenced row is exceeded.CryptoException- If encryption fails. This exception never happens if encryption is not applied.ShutdownException- If this update operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this update operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
updateAll
public void updateAll(ColVal<?>... colVals) throws UnsupportedOperationException, NullPointerException, IllegalArgumentException, MaximumException, CryptoException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Parameters:
colVals- The array of column values.- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- If the array of column values is equal tonullor contains an element equal tonull.IllegalArgumentException- If the array of column values contains at least one column that is not a column of the table. This exception also happens if for at least one value the length of the byte representation of the value (or one of the elements if the value is an array value) exceeds the maximum length allowed by this type. Furthermore, this exception happens if for at least one value the value is a reference and the reference points to a row that does not exist within the referenced table or if the reference points to a row gap or if the value is an array of references and this condition is satisfied for at least one of the references contained in the array.MaximumException- If a new memory block in the VL file space must be allocated and its file position exceeds the maximum allowed position or if the maximum value of the reference counter of a referenced row is exceeded.CryptoException- If encryption fails. This exception never happens if encryption is not applied.ShutdownException- If this update operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this update operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
updateAllSupplyValues
public <T> void updateAllSupplyValues(Column<T> column, Table.ValueSupplier<T> valueSupplier) throws UnsupportedOperationException, NullPointerException, IllegalArgumentException, ImplementationRestrictionException, MaximumException, CryptoException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Type Parameters:
T- The type of the column's values.- Parameters:
column- The column to be updated.valueSupplier- The value supplier.- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- If one of the arguments is equal tonull.IllegalArgumentException- If the column is not a column of the table. This exception also happens if for a value returned by the value supplier the length of the byte representation of the value (or one of the elements if the value is an array value) exceeds the maximum length allowed by this type. Furthermore, this exception happens if the value is a reference and the reference points to a row that does not exist within the referenced table or if the reference points to a row gap or if the value is an array of references and this condition is satisfied for at least one of the references contained in the array.ImplementationRestrictionException- If the number of row gaps is greater thanInteger.MAX_VALUE.MaximumException- If a new memory block in the VL file space must be allocated and its file position exceeds the maximum allowed position or if the maximum value of the reference counter of a referenced row is exceeded.CryptoException- If encryption fails. This exception never happens if encryption is not applied.ShutdownException- If this update operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this update operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
updateAllChangeValues
public <T> void updateAllChangeValues(Column<T> column, Table.ValueChanger<T> valueChanger) throws UnsupportedOperationException, NullPointerException, IllegalArgumentException, ImplementationRestrictionException, MaximumException, CryptoException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Type Parameters:
T- The type of the column's values.- Parameters:
column- The column to be updated.valueChanger- The value changer.- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- If one of the arguments is equal tonull.IllegalArgumentException- If the column is not a column of the table. This exception also happens if for a value returned by the value changer the length of the byte representation of the value (or one of the elements if the value is an array value) exceeds the maximum length allowed by this type. Furthermore, this exception happens if the value is a reference and the reference points to a row that does not exist within the referenced table or if the reference points to a row gap or if the value is an array of references and this condition is satisfied for at least one of the references contained in the array.ImplementationRestrictionException- If the number of row gaps is greater thanInteger.MAX_VALUE.MaximumException- If a new memory block in the VL file space must be allocated and its file position exceeds the maximum allowed position or if the maximum value of the reference counter of a referenced row is exceeded.CryptoException- If encryption or decryption fails. This exception never happens if encryption is not applied.ShutdownException- If this update operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this update operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
delete
public void delete(Ref ref) throws UnsupportedOperationException, NullPointerException, DeleteConstraintException, IllegalReferenceException, ShutdownException, ACDPException, UnitBrokenException, IOFailureException - Parameters:
ref- The reference to the row to delete from the table.- Throws:
UnsupportedOperationException- If the database is read-only.NullPointerException- Ifrefisnull.DeleteConstraintException- If the row to delete is referenced by at least one foreign row.IllegalReferenceException- If the reference points to a row that does not exist within the table. This exception never occurs if the reference is a valid reference.ShutdownException- If this delete operation is a Kamikaze write and the synchronization manager is shut down due to a closed database.ACDPException- If this delete operation is called within a read zone.UnitBrokenException- If recording before data fails or if the unit was broken before.IOFailureException- If an I/O error occurs.
-
truncate
public void truncate() throws UnsupportedOperationException, DeleteConstraintException, ACDPException, ShutdownException, IOFailureExceptionSee Table.truncate()- Throws:
UnsupportedOperationException- If this table has an RO store. This can only be the case if the database is an RO database.DeleteConstraintException- If the table contains at least one row which is referenced by a foreign row. This exception never happens if none of the tables in the database reference this table.ACDPException- If the WR database is read-only or if this method is invoked within a read zone.ShutdownException- If the database is closed.IOFailureException- If an I/O error occurs.
-
get
public final Row get(Ref ref, Column<?>... columns) throws NullPointerException, IllegalArgumentException, IllegalReferenceException, CryptoException, ShutdownException, IOFailureException - Parameters:
ref- The reference to the row, not allowed to benull.columns- The array of columns, not allowed to benull. The columns must be columns of this table. If the array of columns is empty then this method behaves as if the array of columns is identical to the table definition.- Returns:
- The row, never
null. - Throws:
NullPointerException- If one of the arguments is equal tonull.IllegalArgumentException- If at least one column in the specified array of columns is not a column of the table.IllegalReferenceException- If the specified reference points to a row that does not exist within the table or if the reference points to a row gap. Such a situation cannot occur ifrefis a valid reference.CryptoException- If decryption fails. This exception never happens if the database does not apply encryption or if the database is an RO database.ShutdownException- If the file channel provider is shut down due to a closed database. This exception never happens if this get operation is executed within a read zone or a unit or if the database is an RO database and the operating mode is "memory packed" (-2) or "memory unpacked" (-3).IOFailureException- If an I/O error occurs. This exception never happens if the database is an RO database and the operating mode is "memory unpacked" (-3).
-
getValue
public final <T> T getValue(Ref ref, Column<T> column) throws NullPointerException, IllegalArgumentException, IllegalReferenceException, CryptoException, ShutdownException, IOFailureException Returns the value stored at the specified row and column in this table.This method has the same effect as invoking
get(ref, column).get(column).In case of table data corruption this read-only operation may throw an exception of a type not listed below. If the database is a writable database then temporary table data corruption may be due to concurrent writes. Invoke this read-only operation inside a read zone or a unit to ensure that no concurrent writes are taken place in the database while this operation is being executed.
- Type Parameters:
T- The type of the value.- Parameters:
ref- The reference to the row, not allowed to benull. The value must be a valid reference.column- The column, not allowed to benull. The column must be a column of this table.- Returns:
- The value stored at the specified row and column.
- Throws:
NullPointerException- If one of the arguments is equal tonull.IllegalArgumentException- If the specified column is not a column of this table.IllegalReferenceException- If the specified reference points to a row that does not exist within this table or if the reference points to a row gap. This exception never occurs if the reference is a valid reference.CryptoException- If decryption fails. This exception never happens if the database does not apply encryption or if the database is an RO database.ShutdownException- If the database is closed. This exception never happens if this get operation is executed within a read zone or a unit or if the database is an RO database and the operating mode is "memory packed" (-2) or "memory unpacked" (-3).IOFailureException- If an I/O error occurs. This exception never happens if the database is an RO database and the operating mode is "memory unpacked" (-3).
-
iterator
public final Table.TableIterator iterator(Column<?>... columns) throws NullPointerException, IllegalArgumentException - Parameters:
columns- The array of columns, not allowed to benull. The columns must be columns of this table. If the array of columns is empty then the iterator behaves as if the array of columns is identical to the table definition.- Returns:
- The iterator, never
null. - Throws:
NullPointerException- If the array of columns is equal tonull.IllegalArgumentException- If at least one column in the specified array of columns is not a column of the table.
-
iterator
public final Table.TableIterator iterator(Ref ref, Column<?>... columns) throws NullPointerException, IllegalArgumentException, IllegalReferenceException - Parameters:
ref- The reference, may benull. The reference must be a valid reference.columns- The array of columns, not allowed to benull. The columns must be columns of this table. If the array of columns is empty then the iterator behaves as if the array of columns is identical to the table definition.- Returns:
- The iterator, never
null. - Throws:
NullPointerException- If one of the arguments is equal tonull.IllegalArgumentException- If at least one column in the specified array of columns is not a column of the table.IllegalReferenceException- If the specified reference points to a row that does not exist within the table. (The reference does not point to a row gap.) Such a situation cannot occur ifrefis a valid reference.
-
iterator
See Table.iterator() -
rows
public final Stream<Row> rows(Column<?>... columns) throws NullPointerException, IllegalArgumentException - Parameters:
columns- The array of columns, not allowed to benull. The columns must be columns of this table. If the array of columns is empty then the stream behaves as if the array of columns is identical to the table definition.- Returns:
- The stream of the table's rows, never
null. All elements of the stream are non-null. - Throws:
NullPointerException- If the array of columns is equal tonull.IllegalArgumentException- If at least one column in the specified array of columns is not a column of the table.
-
refCount
public final long refCount(Ref ref) throws UnsupportedOperationException, NullPointerException, IllegalReferenceException, ShutdownException, IOFailureException - Parameters:
ref- The reference to the row, not allowed to benull. The value must be a valid reference.- Returns:
- The value of the reference counter or -1 if the row has no reference counter because the table is unreferenced.
- Throws:
UnsupportedOperationException- If this table has an RO store. This can only be the case if the database is an RO database.NullPointerException- Ifrefis equal tonull.IllegalReferenceException- If the specified reference points to a row that does not exist within this table or if the reference points to a row gap. This exception never occurs if the reference is a valid reference.ShutdownException- If the database is closed. This exception never happens if this read-only operation is executed within a read zone or a unit.IOFailureException- If an I/O error occurs.
-
compactVL
public final void compactVL() throws UnsupportedOperationException, ACDPException, ShutdownException, IOFailureException- Throws:
UnsupportedOperationException- If this table has an RO store. This can only be the case if the database is an RO database.ACDPException- If the WR database is read-only or if this method is invoked within a read zone.ShutdownException- If the database is closed.IOFailureException- If an I/O error occurs.
-
compactFL
public final void compactFL() throws UnsupportedOperationException, ImplementationRestrictionException, ACDPException, ShutdownException, IOFailureException- Throws:
UnsupportedOperationException- If this table has an RO store. This can only be the case if the database is an RO database.ImplementationRestrictionException- If the number of row gaps in this table or in at least one of the tables referencing that table is greater thanInteger.MAX_VALUE.ACDPException- If the WR database is read-only or if this method is invoked within a read zone.ShutdownException- If the database is closed.IOFailureException- If an I/O error occurs.
-
toString
See Table.toString()
-