Package adams.db
Class SpectrumF
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.db.AbstractTableFacade
-
- adams.db.SpectrumF
-
- 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 SpectrumF extends adams.db.AbstractTableFacade implements SpectrumIntf
Facade for spectrum tables.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected SpectrumIntf
m_DB
the backend.protected static adams.db.FacadeManager<SpectrumF>
m_TableManager
the facade manager.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.db.SpectrumIntf
MAX_NUM_SPECTRUMS_CACHED, TABLE_NAME
-
-
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.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.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.SampleDataIntf
getSampleDataHandler()
Returns the corresponding SampleData handler.static SpectrumF
getSingleton(adams.db.AbstractDatabaseConnection dbcon)
Returns the singleton of the facade.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.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.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.void
stopBulkAdd()
Interrupts a currently running bulk store, if possible.-
Methods inherited from class adams.db.AbstractTableFacade
getDatabaseConnection, getDebug, getTableName, reload, setDebug, updatePrefix
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_TableManager
protected static adams.db.FacadeManager<SpectrumF> m_TableManager
the facade manager.
-
m_DB
protected SpectrumIntf m_DB
the backend.
-
-
Constructor Detail
-
SpectrumF
public SpectrumF(adams.db.AbstractDatabaseConnection dbcon, String tableName)
Constructor.- Parameters:
dbcon
- the database context to usetableName
- the name of the table
-
-
Method Detail
-
getSampleDataHandler
public SampleDataIntf getSampleDataHandler()
Returns the corresponding SampleData handler.- Specified by:
getSampleDataHandler
in interfaceSpectrumIntf
- Returns:
- the corresponding handler
-
init
public boolean init()
Initialise table & sub-tables.- Specified by:
init
in interfaceSpectrumIntf
- Returns:
- success?
-
exists
public boolean exists(int id)
Checks whether the container exists in the database.- Specified by:
exists
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
exists
in interfaceSpectrumIntf
- Parameters:
id
- the database ID of the data container- Returns:
- true if the container exists
-
exists
public boolean exists(String id)
Checks whether the container exists in the database. UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
exists
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
exists
in interfaceSpectrumIntf
- Parameters:
id
- the ID of the data container- Returns:
- true if the container exists
- See Also:
exists(String, String)
-
exists
public boolean exists(String id, String format)
Checks whether the container exists in the database.- Specified by:
exists
in interfaceSpectrumIntf
- 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 interfaceadams.db.DataProvider<Spectrum>
- Specified by:
load
in interfaceSpectrumIntf
- Parameters:
auto_id
- the database ID- Returns:
- Spectrum, or null if not found
-
load
public Spectrum load(String id)
Load a spectrum with given ID. Get from cache if available UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
load
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
load
in interfaceSpectrumIntf
- Parameters:
id
- the ID- Returns:
- Spectrum, or null if not found
- See Also:
load(String, String)
-
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 interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- 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 interfaceSpectrumIntf
- 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 interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the format- Returns:
- Spectrum, or null if not found
-
loadFromDB
public Spectrum loadFromDB(int auto_id, String rlike, boolean raw)
Load a spectrum from DB with given auto_id.- Specified by:
loadFromDB
in interfaceSpectrumIntf
- Parameters:
auto_id
- the databae IDrlike
- regex for chrom nameraw
- 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 interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the formatraw
- 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 id)
Returns the database ID for given spectrum ID. Get from cache if available UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
getDatabaseID
in interfaceSpectrumIntf
- Parameters:
id
- the ID- Returns:
- Spectrum, or null if not found
- See Also:
load(String, String)
-
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 interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- 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 interfaceSpectrumIntf
- Parameters:
fields
- the field namescond
- 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 interfaceSpectrumIntf
- Parameters:
fields
- the field nameswhere
- the where clause, can be nullcond
- 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 interfaceSpectrumIntf
- Parameters:
fields
- the field namestables
- the involved tableswhere
- the where clause, can be nullcond
- 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. Wave numbers get stored.- Specified by:
add
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
add
in interfaceSpectrumIntf
- 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 interfaceSpectrumIntf
- Parameters:
sp
- spectrum HeaderstoreWaveNo
- 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 interfaceSpectrumIntf
- Parameters:
sp
- the spectra to addstoreWaveNo
- whether to store the wave numbers as wellbatchSize
- the maximum number of records in one batchautoCommit
- 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 interfaceSpectrumIntf
-
remove
public boolean remove(String sample_id, boolean keepReport)
Removes the spectrum and its sample data. UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
remove
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
remove
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample ID of the spectrumkeepReport
- if true does not delete associated report- Returns:
- true if no error
- See Also:
SpectrumIntf.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 interfaceSpectrumIntf
- Parameters:
sample_id
- the sample ID of the spectrumformat
- 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 interfaceadams.db.DataProvider<Spectrum>
- Specified by:
remove
in interfaceSpectrumIntf
- Parameters:
id
- the ID of the spectrum to remove from the databasekeepReport
- if true does not delete associated report- Returns:
- true if no error
-
getSingleton
public static SpectrumF getSingleton(adams.db.AbstractDatabaseConnection dbcon)
Returns the singleton of the facade.- Parameters:
dbcon
- the database connection to get the singleton for- Returns:
- the singleton
-
-