Class TableMapClient

All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable, Deflatable<TableMap>, LivenessManager, LivenessNode, LivenessReferent, DynamicNode, TableMap, TransformableTableMap, Serializable

public class TableMapClient
extends TableMapImpl
See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • get

      public Table get​(Object key)
      Description copied from interface: TableMap
      Gets a table with a given key. Note that this causes the current LivenessManager (see LivenessScopeStack) to manage the result if non-null.
      Parameters:
      key - key
      Returns:
      table associated with the key, or null if the key is not present.
    • getWithTransform

      public Table getWithTransform​(Object key, Function<Table,​Table> transform)
      Description copied from interface: TableMap
      Gets a table with a given key, applying the specified transform before returning.
      Parameters:
      key - key
      Returns:
      table associated with the key, or null if the key is not present.
    • getKeySet

      public Object[] getKeySet()
      Description copied from interface: TableMap
      Gets the keys.
      Returns:
      keys
    • entrySet

      public Collection<Map.Entry<Object,​Table>> entrySet()
      Description copied from interface: TableMap
      Gets the entries.
      Returns:
      the entries
    • values

      public Collection<Table> values()
      Description copied from interface: TableMap
      Gets the values.
      Returns:
      values
    • size

      public int size()
      Description copied from interface: TableMap
      Number of tables in the map.
      Returns:
      number of tables in the map.
    • populateKeys

      public TableMap populateKeys​(Object... keys)
      Description copied from interface: TableMap
      When creating the table map, some of the keys that we would like to be there eventually may not exist. This call lets you pre-populate keys, so that at initialization time you can perform the appropriate joins, etc., on empty tables that you expect to be populated in the future.
      Parameters:
      keys - the keys to add to the map
      Returns:
      this TableMap
    • flatten

      public TableMap flatten()
      Description copied from interface: TableMap
      Flattens all of the result tables within the tablemap.
    • preemptiveUpdatesTable

      public TableMap preemptiveUpdatesTable​(int intervalMillis)
      Description copied from interface: TableMap
      Creates preemptive tables out of all of the result tables within the tablemap.
      Parameters:
      intervalMillis - update interval for the preemptive tables
    • apply

      public <R> R apply​(com.fishlib.base.Function.Unary<R,​TableMap> function)
      Description copied from interface: TableMap
      Applies a function to this tableMap. This is useful if you have a reference to a tableMap; but not the database and want to run a series of operations against the table map without each individual operation resulting in a remote method invocation.
      Type Parameters:
      R - the return type of function
      Parameters:
      function - the function to run, its single argument will be this table map.
      Returns:
      the return value of function
    • transformTablesWithKey

      public TableMap transformTablesWithKey​(BiFunction<Object,​Table,​Table> function)
      Description copied from interface: TableMap
      Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.

      The function may be passed a sentinel key, which can be checked with TableMap.isSentinel(Object). On the sentinel key, the function will be passed in an empty table, and is expected to return an empty table of the proper definition. To avoid this sentinel invocation, callers can be explicit and use TableMap.transformTablesWithKey(TableDefinition, BiFunction).

      Parameters:
      function - the bifunction to apply to each table in this TableMap
      Returns:
      a new TableMap where each table has had function applied
    • transformTablesWithKey

      public TableMap transformTablesWithKey​(TableDefinition returnDefinition, BiFunction<Object,​Table,​Table> function)
      Description copied from interface: TableMap
      Applies a transformation function on all tables in the TableMap, producing a new TableMap which will update as new keys are added.
      Parameters:
      returnDefinition - the table definition for the tables the function will return
      function - the bifunction to apply to each table in this TableMap
      Returns:
      a new TableMap where each table has had function applied
    • transformTablesWithMap

      public TableMap transformTablesWithMap​(TableMap otherMap, BiFunction<Table,​Table,​Table> function)
      Description copied from interface: TableMap
      Applies a BiFunction function on all tables in this TableMap and otherMap that have matching keys, producing a new TableMap which will update as new keys are added. Only applies the function to tables which exist in both maps.
      Parameters:
      otherMap - the other TableMap
      function - the function to apply to each table in this TableMap, the tables in this map are the first argument the tables in the other map are the second argument.
      Returns:
      a new TableMap where each table has had function applied
    • asTable

      public Table asTable​(boolean strictKeys, boolean allowCoalesce, boolean sanityCheckJoins)
      Description copied from interface: TransformableTableMap
      Create a Table out of this TableMap's values.

      Creates a proxy object that in many respects acts like a Table, you can perform many of the table operations on it, which are then applied using TableMap.transformTables(java.util.function.Function) or TableMap.transformTablesWithMap(TableMap, BiFunction) if the right hand side of an operation is another TableMap.

      The returned table acts as if it were an uncoalesced table; when two of our Proxy objects are operated on together, e.g., by a Table.join(com.illumon.iris.db.tables.Table)) operation, then tables with identical keys are used. If strictKeys is set, an error occurs if the two TableMaps do not have identical keySets.

      Supported operations include those which return a Table, LongSizedDataStructure.size(), Table.getDefinition() and operations to retrieve attributes. Operations which retrieve data (such as Table.getIndex()} or Table.getColumn(int) require a coalesce operation. If allowCoalesce is not set to true, then the coalescing operations will fail with an IllegalArgumentException.

      Parameters:
      strictKeys - if we should fail when our RHS TableMap does not have the same keySet
      allowCoalesce - if we should allow this TableMap to be automatically coalesced into a table
      sanityCheckJoins - if we should sanity check join keys, meaning that we should refuse to perform any joins if the join keys would span two segments of the TableMap. This option is safer, but requires additional work on the query engine to perform the safety checks.
      Returns:
      a Table object that performs operations by segment
    • merge

      public Table merge()
      Description copied from interface: TransformableTableMap
      Merges all of the component tables into a single Table.
      Returns:
      all of our component tables merged into a single Table.
    • getId

      public int getId()
    • onKeyAddition

      public void onKeyAddition​(Object key)
    • initializeTransientFieldsForLiveness

      @VisibleForTesting public final void initializeTransientFieldsForLiveness()
      Package-private for Serializable sub-classes to use in readObject only. Public to allow unit tests in another package to work around mock issues where the constructor is never invoked.
    • tryRetainReference

      public final boolean tryRetainReference()
      Description copied from interface: LivenessReferent
      If this referent is "live", behave as LivenessReferent.retainReference() and return true. Otherwise, returns false rather than throwing an exception.
      Specified by:
      tryRetainReference in interface LivenessReferent
      Returns:
      True if this referent was retained, false otherwise
    • dropReference

      public final void dropReference()
      Description copied from interface: LivenessReferent
      Drop a previously-retained reference to this referent.
      Specified by:
      dropReference in interface LivenessReferent
    • getWeakReference

      public WeakReference<? extends LivenessReferent> getWeakReference()
      Description copied from interface: LivenessReferent
      Get a WeakReference to this referent. This may be cached, or newly created.
      Specified by:
      getWeakReference in interface LivenessReferent
      Returns:
      A new or cached reference to this referent
    • tryManage

      public final boolean tryManage​(@NotNull LivenessReferent referent)
      Description copied from interface: LivenessManager
      Attempt to add the specified referent to this manager.
      Specified by:
      tryManage in interface LivenessManager
      Parameters:
      referent - The referent to add
      Returns:
      Whether the referent was in fact added
    • onReferenceCountAtZero

      protected final void onReferenceCountAtZero()
      Description copied from class: ReferenceCounted
      Callback method that will be invoked when the reference count returns to zero.
      Specified by:
      onReferenceCountAtZero in class ReferenceCounted