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.TableInterface, Serializable

    public class SpectrumT
    extends adams.db.wrapper.AbstractWrapper<SpectrumIntf>
    implements SpectrumIntf
    Allows mirroring to another database.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_TableManager

        protected static adams.db.wrapper.WrapperManager<SpectrumT> m_TableManager
        the table manager.
      • m_DB

        protected SpectrumIntf m_DB
        the non-mirrored backend.
      • m_Updating

        protected final String m_Updating
        object for blocking polling/removal of fully processed.
    • Constructor Detail

      • SpectrumT

        protected SpectrumT​(adams.db.AbstractDatabaseConnection dbcon,
                            SpectrumIntf wrapped)
        Initializes the mirroring.
        Parameters:
        dbcon - the database connection
        wrapped - the mirror
    • Method Detail

      • init

        public boolean init()
        Initialise table & sub-tables.
        Specified by:
        init in interface SpectrumIntf
        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
      • getDatabaseID

        public int getDatabaseID​(String sample_id,
                                 String format)
        Returns the database ID for given sample ID and type.
        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
      • add

        public Integer add​(Spectrum sp)
        Adds a spectrum to the database. Returns the created auto-id, and sets in Spectrum.
        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 - spectrum Header
        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
      • 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
      • iterate

        public SpectrumIterator iterate​(AbstractSpectrumConditions conditions,
                                        boolean newConnection)
        Returns an iterator over the spectra that were identified by the conditions.
        Specified by:
        iterate in interface SpectrumIntf
        Parameters:
        conditions - the conditions to use
        newConnection - whether to use a separate connection
        Returns:
        the iterator, null if failed to instantiate
      • getSingleton

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