Class AbstractDatasourceSink<T extends PersistentData>

java.lang.Object
com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractSink<T>
com.inductiveautomation.ignition.gateway.storeforward.sinks.AbstractDatasourceSink<T>
Type Parameters:
T - the type of PersistentData that this sink can handle
All Implemented Interfaces:
DataConsumer<T>, DataSink<T>
Direct Known Subclasses:
HistoricalRecordSink

public abstract class AbstractDatasourceSink<T extends PersistentData> extends AbstractSink<T>
An abstract base class for sinks that use a data source to store data.
  • Field Details

    • datasourceName

      protected String datasourceName
    • queryCache

      protected QueryCache queryCache
  • Constructor Details

    • AbstractDatasourceSink

      protected AbstractDatasourceSink(GatewayContext context, StorageId storageId, PersistentFlavor<T> flavor, int batchSize)
      The default constructor for creating instances of AbstractDatasourceSink.
      Parameters:
      context - the GatewayContext used for operations within the sink
      storageId - the storage id used for determining which datasource to store data to
      flavor - the PersistentFlavor that defines the type of data that this sink will write
      batchSize - the number of data that should be written in each batch
  • Method Details

    • startup

      public void startup()
      Description copied from interface: DataSink
      Starts up the data sink.
      Specified by:
      startup in interface DataSink<T extends PersistentData>
      Overrides:
      startup in class AbstractSink<T extends PersistentData>
    • shutdown

      public void shutdown()
      Description copied from interface: DataSink
      Shuts down the data sink.
      Specified by:
      shutdown in interface DataSink<T extends PersistentData>
      Overrides:
      shutdown in class AbstractSink<T extends PersistentData>
    • uninitialize

      protected void uninitialize()
      Description copied from class: AbstractSink
      Uninitializes the sink.
      Overrides:
      uninitialize in class AbstractSink<T extends PersistentData>
    • isAccepting

      public boolean isAccepting()
      Description copied from interface: DataSink
      Determines whether the data sink is currently accepting data.
      Specified by:
      isAccepting in interface DataSink<T extends PersistentData>
      Overrides:
      isAccepting in class AbstractSink<T extends PersistentData>
      Returns:
      true if the data sink is accepting data, false otherwise
    • storeData

      public void storeData(List<T> data) throws DataStorageException
      Description copied from interface: DataConsumer
      Stores a list of persistent data.
      Parameters:
      data - The data to be stored
      Throws:
      DataStorageException - if an error occurs while storing data
    • isDatasourceAvailable

      protected boolean isDatasourceAvailable()
    • getDatasourceName

      public String getDatasourceName()
      Returns the datasource name for this datasource sink.
      Returns:
      the current datasource name for the datasource sink
    • getDatasource

      protected Datasource getDatasource()
      Returns the Datasource for this datasource sink that can be used for data storage.
      Returns:
      the datasource pertaining to this datasource sink
    • useBatching

      protected boolean useBatching()
      Returns whether JDBC batching should be used when inserting data.
      Returns:
      the flag indicating whether batching should be used
    • getQueryCache

      protected QueryCache getQueryCache()
      Returns the QueryCache for the Datasource belonging to this datasource sink.
      Returns:
      the datasource query cache
    • storeToDatasource

      protected void storeToDatasource(Datasource ds, List<T> data) throws DataStorageException
      Stores the list of supported T PersistentData to the database. First, batching is done, and then the operation is handed off to storeToConnection(SRConnection, List)

      A commit occurs once all batches execute. If a failure occurs, then the transaction is rolled back.

      Parameters:
      ds - the datasource to store persistent data to
      data - the list of persistent data to store
      Throws:
      DataStorageException - if an error occurs while storing data
    • storeToConnection

      protected abstract void storeToConnection(SRConnection conn, List<T> data) throws Exception
      Stores the given data to the specified connection.
      Parameters:
      conn - the connection to store the data to
      data - the data to be stored
      Throws:
      Exception - if there is an error storing the data
    • runFirstTimeChecks

      protected void runFirstTimeChecks(Connection conn) throws SQLException
      Runs a series of checks on the connection before allowing it to be used for storing data. This includes checking whether the connection supports batch updates, and logging a warning if it does not.
      Parameters:
      conn - the connection to check
      Throws:
      SQLException - if there is an error while running the checks
    • onStorageFailure

      protected void onStorageFailure(List<T> data, Exception e) throws DataStorageException
      Throws:
      DataStorageException