Class AoservTable<K,V extends AoservObject<K,V>>
- Direct Known Subclasses:
BackupReportTable
,BankTransactionTable
,CachedTable
,FileReplicationLogTable
,FilesystemCachedTable
,GlobalTable
,ProcessTable
,ServerStatTable
,SpamMessageTable
AoservTable
provides access to one
set of AoservObject
s. The subclasses often provide additional
methods for manipulating the data outside the scope
of a single AoservObject
.- Author:
- AO Industries, Inc.
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Indicates ascending sort.protected final AoservConnector
static final boolean
Indicates descending sort. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addProgressListener
(ProgressListener listener) final void
addTableListener
(TableListener listener) Registers aTableListener
to be notified when the cached data for this table expires.final void
addTableListener
(TableListener listener, long batchTime) Registers aTableListener
to be notified when the cached data for this table expires.final void
addTableLoadListener
(TableLoadListener listener, Object param) void
Clears the cache, freeing up memory.abstract V
Deprecated.Always try to lookup by specific keys; the compiler will help you more when types change.int
Gets an approximate number of accessible rows in the database.final AoservConnector
protected abstract AoservTable.OrderBy[]
Gets the default sorting for this table.final SqlExpression[]
getIndexedRows
(int col, int value) Gets the rows in a more efficient, indexed manner.getIndexedRows
(int col, Object value) Gets the rows in a more efficient, indexed manner.getMap()
Gets a Map-compatible view of this table.protected V
protected V
getObject
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) Gets a single object ornull
when not found.getObjects
(boolean allowRetry, AoservProtocol.CommandId commandId, AoservWritable param1) Limited toInteger.MAX_VALUE
rows.getObjects
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) protected void
getObjects
(boolean allowRetry, List<V> list, AoservProtocol.CommandId commandId, Object... params) getObjectsNoProgress
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) Limited toInteger.MAX_VALUE
rows.protected void
getObjectsNoProgress
(boolean allowRetry, List<V> list, AoservProtocol.CommandId commandId, Object... params) getRows()
Gets the list of all accessible rows.Gets a modifiable copy of the rows, which may then be manipulated, such as for sorting.final int
getSize()
This is size for JavaBeans compatibility.protected ComparisonSortAlgorithm
<Object> Gets the ComparisonSortAlgorithm used to sort the table.abstract Table.TableId
Gets the unique identifier for this table.final String
final Table
final V
getUniqueRow
(int col, int value) final V
getUniqueRow
(int col, long value) final V
getUniqueRow
(int col, short value) final V
getUniqueRow
(int col, Object value) protected abstract V
getUniqueRowImpl
(int col, Object value) Gets a row given a unique column value.boolean
handleCommand
(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive) final boolean
Checks if this table has at least one listener.final boolean
hasTableListener
(TableListener listener) boolean
isEmpty()
boolean
isLoaded()
Checks if the table is loaded.iterator()
final void
printTable
(AoservConnector conn, PrintWriter out, boolean isInteractive) Prints the contents of this table.final void
removeProgressListener
(ProgressListener listener) Removes aProgressListener
from the list of objects being notified as this table is being loaded.final void
removeTableListener
(TableListener listener) Removes aTableListener
from the list of objects being notified when the data is updated.final void
removeTableLoadListener
(TableLoadListener listener) Removes aTableLoadListener
from the list of objects being notified when the table is being loaded.int
size()
protected void
sortIfNeeded
(List<V> list) Sorts the table using the default sort columns and orders.final String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
connector
-
ASCENDING
public static final boolean ASCENDINGIndicates ascending sort.- See Also:
-
DESCENDING
public static final boolean DESCENDINGIndicates descending sort.- See Also:
-
-
Constructor Details
-
AoservTable
-
-
Method Details
-
addProgressListener
-
hasAnyTableListener
public final boolean hasAnyTableListener()Checks if this table has at least one listener. -
hasTableListener
-
addTableListener
Registers aTableListener
to be notified when the cached data for this table expires. The default of 1000ms of batching is used.- Specified by:
addTableListener
in interfaceTable<K>
- See Also:
-
addTableListener
Registers aTableListener
to be notified when the cached data for this table expires. Repitative incoming requests will be batched into fewer events, in increments provided by batchTime. If batchTime is 0, the event is immediately and always distributed. Batched events are performed in concurrent Threads, while immediate events are triggered by the central cache invalidation thread. In other words, don't use a batchTime of zero unless you absolutely need your code to run immediately, because it causes serial processing of the event and may potentially slow down the responsiveness of the server.- Specified by:
addTableListener
in interfaceTable<K>
-
addTableLoadListener
-
clearCache
public void clearCache()Clears the cache, freeing up memory. The data will be reloaded upon next use. -
getConnector
-
getDefaultOrderBy
Gets the default sorting for this table.- Returns:
null
if the sorting is performed by the server or the array of column names
-
getDefaultOrderBySqlExpressions
- Throws:
SQLException
IOException
-
getNewObject
- Throws:
IOException
-
getObject
protected V getObject(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException Gets a single object ornull
when not found.- Throws:
IOException
SQLException
-
getObjects
protected List<V> getObjects(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
getObjects
protected void getObjects(boolean allowRetry, List<V> list, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
getObjects
protected List<V> getObjects(boolean allowRetry, AoservProtocol.CommandId commandId, AoservWritable param1) throws IOException, SQLException Limited toInteger.MAX_VALUE
rows.- Throws:
IOException
SQLException
- See Also:
-
getObjectsNoProgress
protected void getObjectsNoProgress(boolean allowRetry, List<V> list, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
getObjectsNoProgress
protected List<V> getObjectsNoProgress(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException Limited toInteger.MAX_VALUE
rows.- Throws:
IOException
SQLException
- See Also:
-
getSortAlgorithm
Gets the ComparisonSortAlgorithm used to sort the table.Implementation Note:
Defaults toJavaSort
. -
sortIfNeeded
Sorts the table using the default sort columns and orders. If no defaults have been provided, then the table is not sorted.- Throws:
SQLException
IOException
- See Also:
-
getCachedRowCount
Gets an approximate number of accessible rows in the database.- Throws:
IOException
SQLException
- See Also:
-
getRows
Gets the list of all accessible rows.- Specified by:
getRows
in interfaceTable<K>
- Returns:
- a
List
containing all of the rows - Throws:
IOException
- if unable to access the serverSQLException
- if unable to access the database- See Also:
-
getRowsCopy
Gets a modifiable copy of the rows, which may then be manipulated, such as for sorting.This gives the table implementation a way to create a defensive copy most efficient to its underlying storage mechanism.
Note: It is best to use
getSortAlgorithm()
when sorting rows, as the choice of sorting can be very important when objects are pulled from non-heap source like filesystem-based objects. It is very easy for the sort itself to end up pulling all objects into heap.- Throws:
IOException
SQLException
- See Also:
-
getTableId
Gets the unique identifier for this table. Each table has a unique identifier, as defined inSchemaTable.TableId
.- Returns:
- the identifier for this table
- See Also:
-
getTableSchema
- Throws:
IOException
SQLException
-
getTableName
- Specified by:
getTableName
in interfaceTable<K>
- Throws:
IOException
SQLException
-
getIndexedRows
Gets the rows in a more efficient, indexed manner.- Throws:
UnsupportedOperationException
- if not supported by the specific table implementationIOException
SQLException
-
getIndexedRows
Gets the rows in a more efficient, indexed manner.Implementation Note:
This default implementation simply throws UnsupportedOperationException.- Throws:
UnsupportedOperationException
- if not supported by the specific table implementationIOException
SQLException
-
getUniqueRow
- Throws:
IOException
SQLException
-
getUniqueRow
- Throws:
IOException
SQLException
-
getUniqueRow
- Throws:
IOException
SQLException
-
getUniqueRow
- Throws:
IOException
SQLException
-
getUniqueRowImpl
Gets a row given a unique column value.- Parameters:
col
- the column index to searchvalue
- whennull
, no row is matched, even if there is a single row with a uniquelynull
value- Throws:
IOException
SQLException
-
handleCommand
public boolean handleCommand(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive) throws IOException, SQLException - Throws:
IOException
SQLException
-
isLoaded
public boolean isLoaded()Checks if the table is loaded. A table is considered loaded when accessing any part of it will be done entirely locally, avoiding any network traffic. -
printTable
public final void printTable(AoservConnector conn, PrintWriter out, boolean isInteractive) throws IOException, SQLException Prints the contents of this table.- Throws:
IOException
SQLException
-
removeProgressListener
Removes aProgressListener
from the list of objects being notified as this table is being loaded. -
removeTableListener
Removes aTableListener
from the list of objects being notified when the data is updated.- Specified by:
removeTableListener
in interfaceTable<K>
-
removeTableLoadListener
Removes aTableLoadListener
from the list of objects being notified when the table is being loaded. -
toString
-
iterator
-
getMap
Gets a Map-compatible view of this table. -
get
Deprecated.Always try to lookup by specific keys; the compiler will help you more when types change.Gets the value for the associated key ornull
if the data doesn't exist or is filtered.- Parameters:
key
- whennull
, will always returnnull
- Throws:
IOException
SQLException
-
isEmpty
- Throws:
IOException
SQLException
-
size
- Throws:
IOException
SQLException
-
getSize
This is size for JavaBeans compatibility.- Throws:
IOException
SQLException
-