Package com.aoindustries.aoserv.client
Class AOServTable<K,V extends AOServObject<K,V>>
- java.lang.Object
-
- com.aoindustries.aoserv.client.AOServTable<K,V>
-
- Direct Known Subclasses:
BackupReportTable,BankTransactionTable,CachedTable,FileReplicationLogTable,FilesystemCachedTable,GlobalTable,ProcessTable,ServerStatTable,SpamMessageTable
public abstract class AOServTable<K,V extends AOServObject<K,V>> extends Object implements Iterable<V>, Table<V>
AnAOServTableprovides access to one set ofAOServObjects. The subclasses often provide additional methods for manipulating the data outside the scope of a singleAOServObject.- Author:
- AO Industries, Inc.
- See Also:
AOServObject
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAOServTable.OrderBy
-
Field Summary
Fields Modifier and Type Field Description static booleanASCENDINGIndicates ascending sort.protected AOServConnectorconnectorstatic booleanDESCENDINGIndicates descending sort.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAOServTable(AOServConnector connector, Class<V> clazz)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddProgressListener(ProgressListener listener)voidaddTableListener(TableListener listener)Registers aTableListenerto be notified when the cached data for this table expires.voidaddTableListener(TableListener listener, long batchTime)Registers aTableListenerto be notified when the cached data for this table expires.voidaddTableLoadListener(TableLoadListener listener, Object param)voidclearCache()Clears the cache, freeing up memory.abstract Vget(Object key)Deprecated.Always try to lookup by specific keys; the compiler will help you more when types change.intgetCachedRowCount()Gets an approximate number of accessible rows in the database.AOServConnectorgetConnector()protected abstract AOServTable.OrderBy[]getDefaultOrderBy()Gets the default sorting for this table.SQLExpression[]getDefaultOrderBySQLExpressions()List<V>getIndexedRows(int col, int value)Gets the rows in a more efficient, indexed manner.List<V>getIndexedRows(int col, Object value)Gets the rows in a more efficient, indexed manner.Map<K,V>getMap()Gets a Map-compatible view of this table.protected VgetNewObject()protected VgetObject(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)Gets a single object ornullwhen not found.protected List<V>getObjects(boolean allowRetry, AoservProtocol.CommandID commID, AOServWritable param1)Limited toInteger.MAX_VALUErows.protected List<V>getObjects(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)protected voidgetObjects(boolean allowRetry, List<V> list, AoservProtocol.CommandID commID, Object... params)protected List<V>getObjectsNoProgress(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)Limited toInteger.MAX_VALUErows.protected voidgetObjectsNoProgress(boolean allowRetry, List<V> list, AoservProtocol.CommandID commID, Object... params)List<V>getRows()Gets the list of all accessible rows.abstract List<V>getRowsCopy()Gets a modifiable copy of the rows, which may then be manipulated, such as for sorting.intgetSize()This is size for JavaBeans compatibility.protected ComparisonSortAlgorithm<Object>getSortAlgorithm()Gets the ComparisonSortAlgorithm used to sort the table.abstract Table.TableIDgetTableID()Gets the unique identifier for this table.StringgetTableName()TablegetTableSchema()VgetUniqueRow(int col, int value)VgetUniqueRow(int col, long value)VgetUniqueRow(int col, short value)VgetUniqueRow(int col, Object value)protected abstract VgetUniqueRowImpl(int col, Object value)Gets a row given a unique column value.booleanhandleCommand(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive)booleanhasAnyTableListener()Checks if this table has at least one listener.booleanhasTableListener(TableListener listener)booleanisEmpty()booleanisLoaded()Checks if the table is loaded.Iterator<V>iterator()voidprintTable(AOServConnector conn, PrintWriter out, boolean isInteractive)Prints the contents of this table.voidremoveProgressListener(ProgressListener listener)Removes aProgressListenerfrom the list of objects being notified as this table is being loaded.voidremoveTableListener(TableListener listener)Removes aTableListenerfrom the list of objects being notified when the data is updated.voidremoveTableLoadListener(TableLoadListener listener)Removes aTableLoadListenerfrom the list of objects being notified when the table is being loaded.intsize()protected voidsortIfNeeded(List<V> list)Sorts the table using the default sort columns and orders.StringtoString()-
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 Detail
-
connector
protected final AOServConnector connector
-
ASCENDING
public static final boolean ASCENDING
Indicates ascending sort.- See Also:
- Constant Field Values
-
DESCENDING
public static final boolean DESCENDING
Indicates descending sort.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AOServTable
protected AOServTable(AOServConnector connector, Class<V> clazz)
-
-
Method Detail
-
addProgressListener
public final void addProgressListener(ProgressListener listener)
-
hasAnyTableListener
public final boolean hasAnyTableListener()
Checks if this table has at least one listener.
-
hasTableListener
public final boolean hasTableListener(TableListener listener)
-
addTableListener
public final void addTableListener(TableListener listener)
Registers aTableListenerto be notified when the cached data for this table expires. The default of 1000ms of batching is used.- Specified by:
addTableListenerin interfaceTable<K>- See Also:
addTableListener(TableListener,long)
-
addTableListener
public final void addTableListener(TableListener listener, long batchTime)
Registers aTableListenerto 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:
addTableListenerin interfaceTable<K>
-
addTableLoadListener
public final void addTableLoadListener(TableLoadListener listener, Object param)
-
clearCache
public void clearCache()
Clears the cache, freeing up memory. The data will be reloaded upon next use.
-
getConnector
public final AOServConnector getConnector()
-
getDefaultOrderBy
protected abstract AOServTable.OrderBy[] getDefaultOrderBy()
Gets the default sorting for this table.- Returns:
nullif the sorting is performed by the server or the array of column names
-
getDefaultOrderBySQLExpressions
public final SQLExpression[] getDefaultOrderBySQLExpressions() throws SQLException, IOException
- Throws:
SQLExceptionIOException
-
getNewObject
protected V getNewObject() throws IOException
- Throws:
IOException
-
getObject
protected V getObject(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException
Gets a single object ornullwhen not found.- Throws:
IOExceptionSQLException
-
getObjects
protected List<V> getObjects(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getObjects
protected void getObjects(boolean allowRetry, List<V> list, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
getObjects
protected List<V> getObjects(boolean allowRetry, AoservProtocol.CommandID commID, AOServWritable param1) throws IOException, SQLException
Limited toInteger.MAX_VALUErows.
-
getObjectsNoProgress
protected void getObjectsNoProgress(boolean allowRetry, List<V> list, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
getObjectsNoProgress
protected List<V> getObjectsNoProgress(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException
Limited toInteger.MAX_VALUErows.
-
getSortAlgorithm
protected ComparisonSortAlgorithm<Object> getSortAlgorithm()
Gets the ComparisonSortAlgorithm used to sort the table.Implementation Note:
Defaults toJavaSort.
-
sortIfNeeded
protected void sortIfNeeded(List<V> list) throws SQLException, IOException
Sorts the table using the default sort columns and orders. If no defaults have been provided, then the table is not sorted.- Throws:
SQLExceptionIOException- See Also:
getDefaultOrderBySQLExpressions()
-
getCachedRowCount
public int getCachedRowCount() throws IOException, SQLExceptionGets an approximate number of accessible rows in the database.- Throws:
IOExceptionSQLException- See Also:
size()
-
getRows
public List<V> getRows() throws IOException, SQLException
Gets the list of all accessible rows.- Specified by:
getRowsin interfaceTable<K>- Returns:
- a
Listcontaining all of the rows - Throws:
IOException- if unable to access the serverSQLException- if unable to access the database- See Also:
getRowsCopy()
-
getRowsCopy
public abstract List<V> getRowsCopy() throws IOException, SQLException
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:
IOExceptionSQLException- See Also:
getRows(),getSortAlgorithm()
-
getTableID
public abstract Table.TableID 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:
Table.TableID
-
getTableSchema
public final Table getTableSchema() throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getTableName
public final String getTableName() throws IOException, SQLException
- Specified by:
getTableNamein interfaceTable<K>- Throws:
IOExceptionSQLException
-
getIndexedRows
public final List<V> getIndexedRows(int col, int value) throws IOException, SQLException
Gets the rows in a more efficient, indexed manner.- Throws:
UnsupportedOperationException- if not supported by the specific table implementationIOExceptionSQLException
-
getIndexedRows
public List<V> getIndexedRows(int col, Object value) throws IOException, SQLException
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 implementationIOExceptionSQLException
-
getUniqueRow
public final V getUniqueRow(int col, int value) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getUniqueRow
public final V getUniqueRow(int col, long value) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getUniqueRow
public final V getUniqueRow(int col, Object value) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getUniqueRow
public final V getUniqueRow(int col, short value) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
getUniqueRowImpl
protected abstract V getUniqueRowImpl(int col, Object value) throws IOException, SQLException
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 uniquelynullvalue- Throws:
IOExceptionSQLException
-
handleCommand
public boolean handleCommand(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
removeProgressListener
public final void removeProgressListener(ProgressListener listener)
Removes aProgressListenerfrom the list of objects being notified as this table is being loaded.
-
removeTableListener
public final void removeTableListener(TableListener listener)
Removes aTableListenerfrom the list of objects being notified when the data is updated.- Specified by:
removeTableListenerin interfaceTable<K>
-
removeTableLoadListener
public final void removeTableLoadListener(TableLoadListener listener)
Removes aTableLoadListenerfrom the list of objects being notified when the table is being loaded.
-
get
@Deprecated public abstract V get(Object key) throws IOException, SQLException
Deprecated.Always try to lookup by specific keys; the compiler will help you more when types change.Gets the value for the associated key ornullif the data doesn't exist or is filtered.- Parameters:
key- whennull, will always returnnull- Throws:
IOExceptionSQLException
-
isEmpty
public boolean isEmpty() throws IOException, SQLException- Throws:
IOExceptionSQLException
-
size
public int size() throws IOException, SQLException- Throws:
IOExceptionSQLException
-
getSize
public final int getSize() throws IOException, SQLExceptionThis is size for JavaBeans compatibility.- Throws:
IOExceptionSQLException
-
-