Class SpectrumT

  • All Implemented Interfaces:
    adams.core.logging.LoggingSupporter, adams.core.SizeOfHandler, adams.db.DatabaseConnectionProvider, adams.db.DatabaseConnectionUser, adams.db.DataProvider<Spectrum>, SpectrumIntf, adams.db.SQLIntf, adams.db.TableInterface, adams.event.DatabaseConnectionChangeListener, Serializable
    Direct Known Subclasses:
    SpectrumT, SpectrumT, SpectrumT, SpectrumT, SpectrumT

    public abstract class SpectrumT
    extends adams.db.AbstractIndexedTable
    implements SpectrumIntf
    Manages Spectrum tables. Spectrums can be cached, see the Performance class.
    Author:
    dale
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean m_BulkAddStopped
      whether to stop the bulk add.
      protected static adams.db.TableManager<SpectrumT> m_TableManager
      the table manager.
      • Fields inherited from class adams.db.AbstractIndexedTable

        m_init
      • Fields inherited from class adams.db.AbstractTable

        FILENAME, m_AnsiQuotes, m_Properties, m_TableName
      • Fields inherited from class adams.db.generic.SQL

        m_DatabaseConnection, m_Debug, m_Queries, m_Quirks
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
      • Fields inherited from interface adams.db.SQLIntf

        FAKE_TABLE_NAME
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SpectrumT​(adams.db.AbstractDatabaseConnection dbcon)
      Constructor - initalise with database connection.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Integer add​(Spectrum sp)
      Adds a spectrum to the database.
      Integer add​(Spectrum sp, boolean storeWaveNo)
      Adds a spectrum to the database.
      protected StringBuilder addQuery​(Spectrum sp, boolean storeWaveNo)
      Generates the query string for adding a spectrum.
      boolean bulkAdd​(Spectrum[] sp, boolean storeWaveNo, int batchSize, boolean autoCommit, boolean newConnection)
      Stores the spectra in the database.
      boolean exists​(int id)
      Checks whether the container exists in the database.
      boolean exists​(String id)
      Checks whether the container exists in the database.
      boolean exists​(String id, String format)
      Checks whether the container exists in the database.
      protected adams.db.ColumnMapping getColumnMapping()
      Return columns for this table.
      int getDatabaseID​(String id)
      Returns the database ID for given spectrum ID.
      int getDatabaseID​(String sample_id, String format)
      Returns the database ID for given sample ID and type.
      protected adams.db.indices.Indices getIndices()
      Return indices for this table.
      static SpectrumIntf getSingleton​(adams.db.AbstractDatabaseConnection dbcon)
      Returns the singleton of the table (active).
      List<String> getValues​(String[] fields, SpectrumIDConditions cond)
      returns all the specified fields in the database, separated by TABs.
      List<String> getValues​(String[] fields, String where, SpectrumIDConditions cond)
      returns all the specified fields in the database, separated by TABs.
      List<String> getValues​(String[] fields, String tables, String where, SpectrumIDConditions cond)
      returns all the specified fields in the database, separated by TABs.
      boolean init()
      Initialise table & sub-tables.
      static void initTable​(adams.db.AbstractDatabaseConnection dbcon)
      Initializes the table.
      Spectrum load​(int auto_id)
      Load a spectrum with given database ID.
      Spectrum load​(String id)
      Load a spectrum with given ID.
      Spectrum load​(String sample_id, String format)
      Load a spectrum with given sample ID and type.
      Spectrum loadFromDB​(int auto_id, String rlike, boolean raw)
      Load a spectrum from DB with given auto_id.
      Spectrum loadFromDB​(String sample_id, String format, boolean raw)
      Load a spectrum from DB with given sample_id and format.
      Spectrum loadRaw​(int auto_id)
      Load a data container with given auto_id, without passing it through the global filter.
      Spectrum loadRaw​(String sample_id, String format)
      Load a spectrum with given sample ID and type, without filtering through the global container filter.
      protected String pointsToString​(Spectrum sp, boolean storeWaveNo)
      Turns the spectrum points into a string to be stored in the database.
      boolean remove​(int id, boolean keepReport)
      Removes the spectrum and its sample data.
      boolean remove​(String sample_id, boolean keepReport)
      Removes the spectrum and its sample data.
      boolean remove​(String sample_id, String format, boolean keepReport)
      Removes the spectrum and its sample data.
      protected Spectrum resultsetToSpectrum​(ResultSet rs, boolean raw)
      Turns a ResultSet into a spectrum.
      void stopBulkAdd()
      Interrupts a currently running bulk store, if possible.
      • Methods inherited from class adams.db.AbstractIndexedTable

        columnsMatch, columnsMatchTest, create, getAllColumns, getTables, initTables, isThere, postCreate, select, select, selectDistinct, selectDistinct, truncate, update
      • Methods inherited from class adams.db.AbstractTable

        columnExists, databaseConnectionStateChanged, getProperties, getQueries, getTableName, isEnabled, quoteName, tableExists, toString, useAnsiQuotes
      • Methods inherited from class adams.db.generic.SQL

        columnExists, doSelect, drop, execute, executeGeneratedKeys, getDatabaseConnection, getDebug, getMaxColumnNameLength, getResultSet, getSimpleResultSet, prepareStatement, prepareStatement, prepareStatement, select, selectDistinct, selectDouble, selectInt, selectLong, selectString, selectStrings, setDebug, singleton, tableExists, truncate, update, updatePrefix, updateTableName
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.db.DatabaseConnectionProvider

        getDatabaseConnection
      • Methods inherited from interface adams.core.logging.LoggingSupporter

        getLogger, isLoggingEnabled
      • Methods inherited from interface adams.db.TableInterface

        getTableName
    • Field Detail

      • m_TableManager

        protected static adams.db.TableManager<SpectrumT> m_TableManager
        the table manager.
      • m_BulkAddStopped

        protected boolean m_BulkAddStopped
        whether to stop the bulk add.
    • Constructor Detail

      • SpectrumT

        protected SpectrumT​(adams.db.AbstractDatabaseConnection dbcon)
        Constructor - initalise with database connection.
        Parameters:
        dbcon - the database context this table is used in
    • Method Detail

      • init

        public boolean init()
        Initialise table & sub-tables.
        Specified by:
        init in interface SpectrumIntf
        Overrides:
        init in class adams.db.AbstractIndexedTable
        Returns:
        success?
      • exists

        public boolean exists​(int id)
        Checks whether the container exists in the database.
        Specified by:
        exists in interface adams.db.DataProvider<Spectrum>
        Specified by:
        exists in interface SpectrumIntf
        Parameters:
        id - the database ID of the data container
        Returns:
        true if the container exists
      • exists

        public boolean exists​(String id,
                              String format)
        Checks whether the container exists in the database.
        Specified by:
        exists in interface SpectrumIntf
        Parameters:
        id - the ID of the data container
        Returns:
        true if the container exists
      • load

        public Spectrum load​(int auto_id)
        Load a spectrum with given database ID. Get from cache if available
        Specified by:
        load in interface adams.db.DataProvider<Spectrum>
        Specified by:
        load in interface SpectrumIntf
        Parameters:
        auto_id - the database ID
        Returns:
        Spectrum, or null if not found
      • load

        public Spectrum load​(String sample_id,
                             String format)
        Load a spectrum with given sample ID and type. Get from cache if available
        Specified by:
        load in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID
        format - the format
        Returns:
        Spectrum, or null if not found
      • loadRaw

        public Spectrum loadRaw​(int auto_id)
        Load a data container with given auto_id, without passing it through the global filter.
        Specified by:
        loadRaw in interface SpectrumIntf
        Parameters:
        auto_id - the databae ID
        Returns:
        the data container, or null if not found
      • loadRaw

        public Spectrum loadRaw​(String sample_id,
                                String format)
        Load a spectrum with given sample ID and type, without filtering through the global container filter.
        Specified by:
        loadRaw in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID
        format - the format
        Returns:
        Spectrum, or null if not found
      • resultsetToSpectrum

        protected Spectrum resultsetToSpectrum​(ResultSet rs,
                                               boolean raw)
                                        throws Exception
        Turns a ResultSet into a spectrum.
        Parameters:
        rs - the ResultSet to use
        raw - whether to return the raw spectrum or filter through the global container filter
        Returns:
        the spectrum, null in case of an error
        Throws:
        Exception - if something goes wrong
      • loadFromDB

        public Spectrum loadFromDB​(int auto_id,
                                   String rlike,
                                   boolean raw)
        Load a spectrum from DB with given auto_id.
        Specified by:
        loadFromDB in interface SpectrumIntf
        Parameters:
        auto_id - the databae ID
        rlike - regex for spectrum ID
        raw - whether to return the raw spectrum or filter it through the global container filter
        Returns:
        Spectrum, or null if not found
      • loadFromDB

        public Spectrum loadFromDB​(String sample_id,
                                   String format,
                                   boolean raw)
        Load a spectrum from DB with given sample_id and format.
        Specified by:
        loadFromDB in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID
        format - the format
        raw - whether to return the raw spectrum or filter it through the global container filter
        Returns:
        Spectrum, or null if not found
      • getDatabaseID

        public int getDatabaseID​(String sample_id,
                                 String format)
        Returns the database ID for given sample ID and type. Get from cache if available
        Specified by:
        getDatabaseID in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID
        format - the format
        Returns:
        the database ID, Constants.NO_ID
      • getValues

        public List<String> getValues​(String[] fields,
                                      SpectrumIDConditions cond)
        returns all the specified fields in the database, separated by TABs.
        Specified by:
        getValues in interface SpectrumIntf
        Parameters:
        fields - the field names
        cond - the conditions for the retrieval
        Returns:
        list of tab-separated values
      • getValues

        public List<String> getValues​(String[] fields,
                                      String where,
                                      SpectrumIDConditions cond)
        returns all the specified fields in the database, separated by TABs.
        Specified by:
        getValues in interface SpectrumIntf
        Parameters:
        fields - the field names
        where - the where clause, can be null
        cond - the conditions for the retrieval
        Returns:
        list of tab-separated values
      • getValues

        public List<String> getValues​(String[] fields,
                                      String tables,
                                      String where,
                                      SpectrumIDConditions cond)
        returns all the specified fields in the database, separated by TABs.
        Specified by:
        getValues in interface SpectrumIntf
        Parameters:
        fields - the field names
        tables - the involved tables
        where - the where clause, can be null
        cond - the conditions for the retrieval
        Returns:
        list of tab-separated values
      • pointsToString

        protected String pointsToString​(Spectrum sp,
                                        boolean storeWaveNo)
        Turns the spectrum points into a string to be stored in the database. Format: wave1:ampltd1,wave2:ampltd2,...
        Parameters:
        sp - the spectrum to convert
        storeWaveNo - whether to store the wave numbers as well
        Returns:
        the generated string
      • addQuery

        protected StringBuilder addQuery​(Spectrum sp,
                                         boolean storeWaveNo)
        Generates the query string for adding a spectrum.
        Parameters:
        sp - the spectrum to turn into query
        storeWaveNo - whether to store the wave numbers as well
        Returns:
        the generated query
      • add

        public Integer add​(Spectrum sp)
        Adds a spectrum to the database. Returns the created auto-id, and sets in Spectrum. Wave numbers get stored.
        Specified by:
        add in interface adams.db.DataProvider<Spectrum>
        Specified by:
        add in interface SpectrumIntf
        Parameters:
        sp - spectrum Header
        Returns:
        new ID, or null if fail
      • add

        public Integer add​(Spectrum sp,
                           boolean storeWaveNo)
        Adds a spectrum to the database. Returns the created auto-id, and sets in Spectrum.
        Specified by:
        add in interface SpectrumIntf
        Parameters:
        sp - the spectrum to add
        storeWaveNo - whether to store the wave numbers as well
        Returns:
        new ID, or null if fail
      • bulkAdd

        public boolean bulkAdd​(Spectrum[] sp,
                               boolean storeWaveNo,
                               int batchSize,
                               boolean autoCommit,
                               boolean newConnection)
        Stores the spectra in the database.
        Specified by:
        bulkAdd in interface SpectrumIntf
        Parameters:
        sp - the spectra to add
        storeWaveNo - whether to store the wave numbers as well
        batchSize - the maximum number of records in one batch
        autoCommit - whether to use auto-commit or not (turning off may impact other transactions!)
        newConnection - uses a separate database connection just for this connection (then no auto-commit doesn't affect the rest)
        Returns:
        true if successfully inserted/updated
      • stopBulkAdd

        public void stopBulkAdd()
        Interrupts a currently running bulk store, if possible.
        Specified by:
        stopBulkAdd in interface SpectrumIntf
      • getColumnMapping

        protected adams.db.ColumnMapping getColumnMapping()
        Return columns for this table.
        Specified by:
        getColumnMapping in class adams.db.AbstractIndexedTable
        Returns:
        database columns
      • getIndices

        protected adams.db.indices.Indices getIndices()
        Return indices for this table.
        Specified by:
        getIndices in class adams.db.AbstractIndexedTable
        Returns:
        indices
      • remove

        public boolean remove​(String sample_id,
                              boolean keepReport)
        Removes the spectrum and its sample data. Uses SampleData.DEFAULT_FORMAT as format.
        Specified by:
        remove in interface adams.db.DataProvider<Spectrum>
        Specified by:
        remove in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID of the spectrum
        keepReport - if true does not delete associated report
        Returns:
        true if no error
        See Also:
        remove(String, String, boolean)
      • remove

        public boolean remove​(String sample_id,
                              String format,
                              boolean keepReport)
        Removes the spectrum and its sample data.
        Specified by:
        remove in interface SpectrumIntf
        Parameters:
        sample_id - the sample ID of the spectrum
        format - the format of the spectrum (eg NIR)
        keepReport - if true does not delete associated report
        Returns:
        true if no error
      • remove

        public boolean remove​(int id,
                              boolean keepReport)
        Removes the spectrum and its sample data.
        Specified by:
        remove in interface adams.db.DataProvider<Spectrum>
        Specified by:
        remove in interface SpectrumIntf
        Parameters:
        id - the ID of the spectrum to remove from the database
        keepReport - if true does not delete associated report
        Returns:
        true if no error
      • initTable

        public static void initTable​(adams.db.AbstractDatabaseConnection dbcon)
        Initializes the table. Used by the "InitializeTables" tool.
        Parameters:
        dbcon - the database context
      • getSingleton

        public static SpectrumIntf getSingleton​(adams.db.AbstractDatabaseConnection dbcon)
        Returns the singleton of the table (active).
        Parameters:
        dbcon - the database connection to get the singleton for
        Returns:
        the singleton