Class DynamicTableWriter

java.lang.Object
com.illumon.iris.db.v2.utils.DynamicTableWriter
All Implemented Interfaces:
Entry, Record, Row, TableWriter

public class DynamicTableWriter extends Object implements TableWriter
The DynamicTableWriter creates an in-memory table using ArrayBackedColumnSources of the type specified in the constructor. You can retrieve the table using the getTable function.

This class is not thread safe, you must synchronize externally.

  • Constructor Details

    • DynamicTableWriter

      public DynamicTableWriter(String[] columnNames, Class<?>[] columnTypes, Map<String,Object> constantValues)
      Creates a TableWriter that produces an in-memory table using the provided column names and types.
      Parameters:
      columnNames - the names of the columns in the output table (and our input)
      columnTypes - the types of the columns in the output table (must be compatible with the input)
      constantValues - a Map of columns with constant values
    • DynamicTableWriter

      public DynamicTableWriter(String[] columnNames, Class<?>[] columnTypes)
      Creates a TableWriter that produces an in-memory table using the provided column names and types.
      Parameters:
      columnNames - the names of the columns in the output table (and our input)
      columnTypes - the types of the columns in the output table (must be compatible with the input)
    • DynamicTableWriter

      public DynamicTableWriter(@NotNull TableDefinition definition)
      Creates a write object that would write an object at a given location
      Parameters:
      definition - The table definition to create the dynamic table writer for
    • DynamicTableWriter

      public DynamicTableWriter(TableDefinition definition, Map<String,Object> constantValues)
      Creates a write object that would write an object at a given location
      Parameters:
      definition - The table definition to create the dynamic table writer for
  • Method Details

    • getTable

      public LiveQueryTable getTable()
      Gets the table created by this DynamicTableWriter.

      The returned table is registered with the LiveTableMonitor, and new rows become visible within the refresh loop.

      Returns:
      a live table with the output of this log
    • getRowWriter

      public Row getRowWriter()
      Returns a row writer, which allocates the row. You may get setters for the row, and then call addRowToTableIndex when you are finished. Because the row is allocated when you call this function, it is possible to get several Row objects before calling addRowToTableIndex.

      This contrasts with DynamicTableWriter.getSetter, which allocates a single row; and you must call DynamicTableWriter.addRowToTableIndex before advancing to the next row.

      Specified by:
      getRowWriter in interface TableWriter
      Returns:
      a Row from which you can retrieve setters and call write row.
    • getSetter

      public RowSetter getSetter(String name)
      Returns a RowSetter for the given column. If required, a Row object is allocated. You can not mix calls with getSetter and getRowWriter. After setting each column, you must call addRowToTableIndex, before beginning to write the next row.
      Specified by:
      getSetter in interface Row
      Specified by:
      getSetter in interface TableWriter
      Parameters:
      name - column name.
      Returns:
      a RowSetter for the given column
    • setFlags

      public void setFlags(Row.Flags flags)
      Description copied from interface: TableWriter

      The implementation is likely to delegate to Row.setFlags(Flags) in a default Row instance.

      Specified by:
      setFlags in interface Row
      Specified by:
      setFlags in interface TableWriter
    • writeRow

      public void writeRow()
      Writes the current row created with the getSetter call, and advances the current row by one.

      The row will be made visible in the table after the LiveTableMonitor refresh cycle completes.

      Specified by:
      writeRow in interface Row
      Specified by:
      writeRow in interface TableWriter
    • logRow

      public void logRow(Map<String,Object> values)
      This is a convenience function so that you can log an entire row at a time using a Map. You must specify all values in the setters map (and can't have any extras). The type of the value must be castable to the type of the setter.
      Parameters:
      values - a map from column name to value for the row to be logged
    • logRow

      public void logRow(Object... values)
      This is a convenience function so that you can log an entire row at a time.
      Parameters:
      values - an array containing values to be logged, in order of the fields specified by the constructor
    • flush

      public void flush()
      Description copied from interface: TableWriter
      Flushes data out.
      Specified by:
      flush in interface TableWriter
    • supportAllTypes

      public boolean supportAllTypes()
      Description copied from interface: TableWriter
      True if all data types can be written out; false otherwise.
      Specified by:
      supportAllTypes in interface TableWriter
      Returns:
      true if all data types can be written out; false otherwise.
    • close

      public void close() throws IOException
      Description copied from interface: TableWriter
      Closes the writer.
      Specified by:
      close in interface TableWriter
      Throws:
      IOException - problem closing the writer.
    • getColumnTypes

      public Class[] getColumnTypes()
      Description copied from interface: TableWriter
      Gets the column types for the table.
      Specified by:
      getColumnTypes in interface TableWriter
      Returns:
      column types for the table.
    • getColumnNames

      public String[] getColumnNames()
      Description copied from interface: TableWriter
      Gets the column names for the table.
      Specified by:
      getColumnNames in interface TableWriter
      Returns:
      column names for the table.